Skip to main content

Google Analytics 4

This page describes how to set up Google Analytics 4 as a destination.

Set up

An example setup for Google Analytics 4 is shown below.

src/pages/api/syft.ts
// ...
const destinations = [
{
type: "ga4",
settings: {
apiSecret: "xxxx"
},
},
];
// ...

Configuration options

NameTypeDescriptionRequiredDefault
measurementIdstringThe Measurement ID associated with a stream. Found in the Google Analytics UI under: Admin > Data Streams > choose your stream > Measurement ID. Required for web streams.false
firebaseAppIdstringThe Firebase App ID associated with the Firebase app. Found in the Firebase console under: Project Settings > General > Your Apps > App ID. Required for mobile app streams.false
apiSecretstringAn API SECRET generated in the Google Analytics UI, navigate to: Admin > Data Streams > choose your stream > Measurement Protocol > Createtrue

Data Modeling

Custom Event

Custom Event

Send any custom event

Matched events

type = "track"

Data Mapping

Destination FieldTypeDescriptionSource Field
data_stream_typestringThe type of data stream this data belongs in. This can either be a web stream or a mobile app stream (iOS or Android). Possible values: "Web" (default) and "Mobile App"."Web"
app_instance_idstringUniquely identifies a specific installation of a Firebase app. This value needs to be retrieved through the Firebase SDK. Required for mobile app streams.$.app_instance_id
clientIdstringUniquely identifies a user instance of a web client. Required for web streams.$.userId ?? $.anonymousId
user_idstringA unique identifier for a user. See Google's User-ID for cross-platform analysis and Reporting: deduplicate user counts documentation for more information on this identifier.$.user_id
timestamp_microsstringA Unix timestamp (in microseconds) for the time to associate with the event. Syft will convert to Unix if not already converted. Events can be backdated up to 3 calendar days based on the property's timezone.$.timestamp
namestringThe unique name of the custom event created in GA4. GA4 does not accept spaces in event names so Syft will replace any spaces with underscores. More information about GA4 event name rules is available in their docs.$.event
lowercasebooleanIf true, the event name will be converted to lowercase before sending to Google. Event names are case sensitive in GA4 so enable this setting to avoid distinct events for casing differences. More information about GA4 event name rules is available in their docs.false
user_propertiesobjectThe user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s Custom user properties to learn how to set and register user properties.$.user_properties
engagement_time_msecnumberThe amount of time a user interacted with your site, in milliseconds. Google only counts users who interact with your site for a non-zero amount of time. By default, Syft sets engagement time to 1 so users are counted.1
paramsobjectThe event parameters to send to Google Analytics 4.$.params
,
Page View

Page View

Send page view when a user views a page

Matched events

type = "page" or type = "screen"

Data Mapping

Destination FieldTypeDescriptionSource Field
data_stream_typestringThe type of data stream this data belongs in. This can either be a web stream or a mobile app stream (iOS or Android). Possible values: "Web" (default) and "Mobile App"."Web"
app_instance_idstringUniquely identifies a specific installation of a Firebase app. This value needs to be retrieved through the Firebase SDK. Required for mobile app streams.$.app_instance_id
clientIdstringUniquely identifies a user instance of a web client. Required for web streams.$.userId ?? $.anonymousId
user_idstringA unique identifier for a user. See Google's User-ID for cross-platform analysis and Reporting: deduplicate user counts documentation for more information on this identifier.$.user_id
timestamp_microsstringA Unix timestamp (in microseconds) for the time to associate with the event. Syft will convert to Unix if not already converted. Events can be backdated up to 3 calendar days based on the property's timezone.$.timestamp
page_locationstringThe current page URL$.context.page.url
page_referrerstringPrevious page URL$.context.page.referrer
user_propertiesobjectThe user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s Custom user properties to learn how to set and register user properties.$.user_properties
page_titlestringThe current page title$.context.page.title
engagement_time_msecnumberThe amount of time a user interacted with your site, in milliseconds. Google only counts users who interact with your site for a non-zero amount of time. By default, Syft sets engagement time to 1 so users are counted.1
paramsobjectThe event parameters to send to Google Analytics 4.$.params
,
Login

Login

Send event when a user logs in

Matched events

type = "identify"

Data Mapping

Destination FieldTypeDescriptionSource Field
data_stream_typestringThe type of data stream this data belongs in. This can either be a web stream or a mobile app stream (iOS or Android). Possible values: "Web" (default) and "Mobile App"."Web"
app_instance_idstringUniquely identifies a specific installation of a Firebase app. This value needs to be retrieved through the Firebase SDK. Required for mobile app streams.$.app_instance_id
client_idstringUniquely identifies a user instance of a web client. Required for web streams.$.userId ?? $.anonymousId
user_idstringA unique identifier for a user. See Google's User-ID for cross-platform analysis and Reporting: deduplicate user counts documentation for more information on this identifier.$.user_id
timestamp_microsstringA Unix timestamp (in microseconds) for the time to associate with the event. Syft will convert to Unix if not already converted. Events can be backdated up to 3 calendar days based on the property's timezone.$.timestamp
methodstringThe method used to login.$.method
user_propertiesobjectThe user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s Custom user properties to learn how to set and register user properties.$.user_properties
engagement_time_msecnumberThe amount of time a user interacted with your site, in milliseconds. Google only counts users who interact with your site for a non-zero amount of time. By default, Syft sets engagement time to 1 so users are counted.1
paramsobjectThe event parameters to send to Google Analytics 4.$.params