Google Analytics 4 (GA4)
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
- TypeScript
- Script
- Code
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);
Load the destination via dynamic import
<script>
// Upload the dist/index.mjs on your own server
const destination = (
await import(
'https://cdn.jsdelivr.net/npm/@elbwalker/destination-web-google-ga4/dist/index.mjs'
)
).default;
elb('walker destination', destination, config);
</script>
Copy the code from the index.browser.js file
(function () {
'use strict';
var Destination = (() => {})(); // This is the copied code
elb('walker destination', Destination.default, config);
})();
Configuration
Configure the GA4 destination with your Measurement ID.
Example
Custom
Property | Type | Description |
---|---|---|
measurementId* | string | GA4 Measurement ID |
debug | boolean | Enables debug mode for additional logging |
include | array | Defines groups of properties to be included in all events, data by default. Use an empty array for none. |
pageview | boolean | Enables or disables automatic pageview tracking |
server_container_url | string | URL for a server-side tag manager |
snakeCase | boolean | Converts parameter names to snake_case for GA4 compatibility |
transport_url | string | URL used for sending events to GA4 |
Properties with a *
are required.
CustomEvent
Property | Type | Description |
---|---|---|
include | array | Specifies which groups of properties to include, e.g., ['all'], ['data'], ['context'], etc. |
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: []
.
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.
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.
purchase
Map your custom walkerOS event to get a purchase gtag.js event.
If you need professional support with your walkerOS implementation, check out our services.