Tracking Google Analytics Events in Salesforce Omnistudio Applications?

Question from user:

Has anyone had success setting up Google tags / triggers with a Salesforce Omnistudio application? Currently I have a community site that contains my omniscripts and I want to be able to track when the generic omniscript “next” button is pressed on the GTM side.

I’m able to see when a user clicks inside the omniruntime container in the site preview, but all of the click events are the same for every component in a particular omniscript.

Seems like more setup is required for this but I’m having troubles finding where. Any help appreciated.

Answer from Nabil:

How do I track Google Analytics events in Salesforce Omnistudio applications?

The issue you’re facing is common because OmniScripts use a Shadow DOM for encapsulation, making it hard for Google Tag Manager (GTM) to reliably target specific internal elements like the “next” button with standard click listeners.

To accurately track the “next” button click, you’ll need a more robust solution than GTM’s built-in click triggers.

A much better long-term and reliable solution is to instrument the OmniScript directly to send custom events to the GTM Data Layer.

Within your OmniScript’s LWC or a custom step, you can use the OmniScript.getData() method to get the current state and then use JavaScript to push a custom event to the Data Layer, like dataLayer.push({event: 'omniscript_next_click', stepName: currentStepName}) whenever the next button is functionally pressed.

You could potentially use an Integration Procedure triggered on step completion to do this as well, though a client-side Data Layer push is usually cleaner for simple button clicks.

Once you have custom events being pushed from OmniScript to the Data Layer, you can create a GTM Custom Event Trigger that fires on omniscript_next_click.

This trigger will be much more reliable than trying to target a generic DOM element.

For advanced tracking and to bypass browser limitations like Intelligent Tracking Prevention (ITP) and Adblockers, consider implementing Server-Side Tagging.

This involves sending the click event data from the Data Layer to a server-side tagging solution like Google Tag Manager Server-Side (GTM-SS) hosted on Google Cloud Platform (GCP) or using a service like Stape.

This would work by sending the omniscript_next_click event to your tagging server, which then securely forwards it to Google Analytics.

The ultimate solution involves linking your OmniScript events with your own data infrastructure.

Salesforce OmniStudio has APIs that allow you to capture data related to the flow’s progress.

You can send this transactional data (like Omniscript_Step_Completed) to a secure backend, and then use the Google Analytics Data API to later reconcile or enhance your Google Analytics data.

For example, the OmniStudio APIs + Google Analytics Data API + GTM/Stape setup is superior because it ensures that critical conversion data isn’t lost due to client-side issues and allows you to join the rich OmniScript data with user behavior data in a privacy-preserving and reliable way, offering a complete, server-validated view of the user journey.

The initial setup is more involved, but the data quality and resilience are significantly higher.

About The Author