Docs
Integration of Google Analytics 4 (GA4) with Chargebee-hosted pages can be done through Google Tag Manager (GTM).
Please note that in-app layout of Checkout functionality does not inherently include a built-in integration with Google Analytics 4 (GA4) or Google Tag Manager (GTM). Instead, we leverage Chargebee.js to facilitate this capability.
Chargebee.js offers two primary functionalities to support analytics integration within the Checkout process:
To harness analytics capabilities within our in-app layout of Checkout, developers can leverage Chargebee.js to create a seamless and tailored analytics experience for their applications.
Browser tracking blockers
Ad-blockers or privacy-enablement software installed on your customers' browser can prevent tracking data from being sent.
Initialize and install GTM on your website, do this by performing steps 1 and 2 of this guide by Google .
If you are setting up GTM for the first time, here are some considerations before you install GTM.
The GTM integration records customer interactions with Chargebee checkout and portal. Back-end operations such as subscription renewals do not trigger any events to GTM.
You can integrate Chargebee with GTM via drop-in script or API.
Enable the data-cb-gtm-enabled
attribute to true when invoking Chargebee JS in the page headers of your site.
<script src="https://js.chargebee.com/v2/chargebee.js"
data-cb-site="you-chargebee-subdomain" data-cb-gtm-enabled="true">
</script>
Replace your-chargebee-subdomain
in the code snippets on this page with your Chargebee site subdomain names.
For example, if your Chargebee site is bigshopper-test.chargebee.com
, then replace your-chargebee-subdomain
with bigshopper-test
.
Pass the enableGTMTracking
parameter as true when initializing the Chargebee instance.
var chargebeeInstance = Chargebee.init({
site: "your-chargebee-subdomain",
enableGTMTracking: true
});
Click Triggers > New.
Click Trigger Configuration and choose the Custom Event trigger type.
Enter the event name as cb_*
and check Use regex matching.
Name the trigger, say CB Event Trigger.
Click Save.
GA4 Configuration tag loads Google Analytics for your Google Analytics 4 property.
This subsection explains how to configure GTM so that events are tracked in GA4 properly. This does not include any transaction or product data. To track transactions, product information, and tracking ecommerce events, implement the steps in the next subsection as well.
cbAction
.Perform the above steps again to create yet another data layer variable. This time, enter the Data Layer Variable Name as cbCategory
and name the variable, say CB Event - Category.
Adding these events to your website or mobile app helps you measure additional features and behavior as well as generate useful reports.
The first section covered the basic setup for tracking non-ecommerce GA events. This section helps you set up additional GTM configurations required for tracking ecommerce events.
chargebee_ecommerce
.ecommerce.purchase.products
.purchase
.items,
and in the value, select the e-commerce data layer variable created before. In our example, GA4 ecommerce data layerOnce you have created the tag, publish the GTM container to make the changes live on the Chargebee-hosted pages.
To publish the GTM container, follow these steps::
You have now successfully integrated Google Analytics 4 with Chargebee-hosted pages through Google Tag Manager. You can now track visitor behavior and user engagement on your website to gain valuable insights into user behavior and make data-driven decisions.
Whenever you make changes to the GTM configuration, ensure that you reload your site, ignoring cached content (i.e. hard refresh). The keyboard shortcuts are:
Mac: ⌘ + Shift + R
Windows/Linux: Ctrl + F5 or Ctrl + Shift + R
You can test your GA tag by checking real-time reports. Remember that it takes 24-48 hours to process non-real-time reports. Refer to, checking your tag setup in Google Analytics .
Learn more about the limitations of GA4 tracking.
Learn more about the events passed to GTM/GA.