Skip to main content

Google Analytics 4 (GA4)

Source code Package Browser ES5

Google Analytics 4 is the current version of Google's marketing measurement software. It's a common analytics tool for tracking conversions and user behavior on websites.

Installation

Install the destination via npm

npm i @elbwalker/destination-web-google-ga4
import { elb } from '@elbwalker/walker.js';
import destinationGoogleGA4 from '@elbwalker/destination-web-google-ga4';

elb('walker destination', destinationGoogleGA4, config);

Configuration

Configure the GA4 destination with your Measurement ID.

Example

Custom Config
Result

Custom

PropertyTypeDescription
measurementId*stringGA4 Measurement ID
debugbooleanEnables debug mode for additional logging
includearrayDefines groups of properties to be included in all events, data by default. Use an empty array for none.
pageviewbooleanEnables or disables automatic pageview tracking
server_container_urlstringURL for a server-side tag manager
snakeCasebooleanConverts parameter names to snake_case for GA4 compatibility
transport_urlstringURL used for sending events to GA4

Properties with a * are required.

CustomEvent

PropertyTypeDescription
includearraySpecifies which groups of properties to include, e.g., ['all'], ['data'], ['context'], etc.
note

include is available at both, the config and event level. Settings on the event level will override the general ones.

Use the string-dot notation (data.id, user.id, group, context.position.0) to access all values of an event. They can either be a string or an object. A string is used as a key to access an event value directly. An object can be used to set a default value. A key to access the event value.

Use the include option to bulk-add event properties without explicitly mapping custom event parameters. This adds all available properties of the specified group. Available groups are event (for basic event properties like trigger, timing, etc.), data, context, globals, nested, source, user, version, or just all. All data properties are added automatically by default. If you don't want this add include: [].

note

consent and nested are not available via include, but you can add them explicitly using data.

The properties get prefixed with the group's name and underscore (like globals_lang for { globals: { lang: 'de' } }). Custom parameters will override include values with the same key.

Mapping

You are able to map your walkerOS events to match the respective requirements of each vendor. The mapping examples are using a live configuration.

tip

The code examples are interactive. You can edit the code to generate your individual event mapping.

add_to_cart

Map your custom walkerOS event to get an add_to_cart gtag.js event.

Event
Custom Config
Result

purchase

Map your custom walkerOS event to get a purchase gtag.js event.

Event
Custom Config
Result
info

If you need professional support with your walkerOS implementation, check out our services.