Docs
You can integrate Google Analytics 4 (GA4) with Chargebee-hosted pages through Google Tag Manager (GTM).
You can integrate GTM for Full Page Checkout via the following integration methods:
Make sure you have a GTM account and a container before proceeding with the setup.
Follow these steps to create an account and container if you haven't yet. Skip these steps if you already have a GTM account and a container.
When you create a new account, you will walk through the steps to set up a new container.
Go to Google Tag Manager .
Select the Accounts tab > Create Account.
Enter an Account Name and select the Country for the account.
Enter a descriptive Container name and select the Target Platform.
Click Create to create a container and agree to the Terms of Service.
Browser tracking blockers
Ad-blockers or privacy-enablement software installed on your customers' browser can prevent tracking data from being sent.
Before you enable and configure tracking, follow the steps mentioned below to get your GTM ID from your Google Tag Manager account. This ID is used to enable Tracking in your Chargebee site.
Once you have the GTM ID, follow these steps:
In your Chargebee site, go to Settings > Configure Chargebee > Checkout & Self-Serve Portal.
Select the Configuration tab and click Enable under the Tracking section (if not enabled already).
Click the arrow pointing down for Google Tag Manager, enter the GTM ID retrieved from your Google Tag Manager account and click Apply.
Click Publish.
Once configured, load the Full Page Checkout to start tracking the events.
You can integrate Chargebee with GTM via a Drop-in script or API.
Before proceeding to the steps for integrating via these methods, initialize and install GTM on your website by performing steps 1 and 2 of this Google guide .
If you are setting up GTM for the first time, here are some considerations before you install GTM.
Let us see how you can use each method to integrate GTM:
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.