Docs

Log in to read the version of docs relevant to your site, or use the dropdown versions

GA4 for In-App Checkout and Portal

Chargebee supports Google Analytics 4 (GA4) by sending checkout and portal events to GA. You can customize your GA4 data collection to meet your business needs using Chargebee's built-in GA integration or custom GA integration. By analyzing user behavior, you can optimize customer experiences, improve conversion rates, and drive growth.

Information

Using Google Tag Manager (GTM)?
If you use Google Tag Manager to connect to your GA4 account, use this separate integration. Do not use both integrations simultaneously.

Setting up GA4 for the first time

Follow these steps to set up analytics data collection on your website:

Prerequisites

  1. Set up a GA4 account and then a GA4 property. Option 1: Setting up analytics data collection for the first time. Option 2: Migrating from UA to GA4. Learn more.

  2. Add the Google tag script: Add the Google tag to your web pages to begin seeing data in your new Google Analytics 4 property. Follow the steps under add the Google tag directly to your web pages on this page. See the video below as a reference to get the Google tag script:

  3. Go to Settings > Configure Chargebee > Checkout & Self Server Portal.

  4. To track and measure purchase events in Chargebee, select the Configuration tab and add your domain under the Add Domain option under Advanced Settings.

Browser tracking blockers:
Ad-blockers or privacy software installed on customers' browsers may prevent tracking data from being sent.

Setting up GA integration

After completing the prerequisites, use Chargebee's built-in GA event tracking or your own custom GA integration to send events to GA using Chargebee JS callbacks.

Built-in GA Integration

When enabled, Chargebee triggers events to GA based on page interactions in the Chargebee Checkout or Portal.

Note:

This integration tracks customer interactions with Chargebee Checkout and Portal. Backend operations, such as subscription renewals, do not trigger events.

You can integrate using a drop-in script or API.

A. Using Drop-in Script

Enable the data-cb-ga-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="your-chargebee-subdomain" data-cb-ga-enabled="true">
</script>

Note:

Replace your-chargebee-subdomain with your Chargebee site subdomain. For example, if your site is bigshopper-test.chargebee.com, the script will be:

<script src="https://js.chargebee.com/v2/chargebee.js"
data-cb-site="bigshopper-test" data-cb-ga-enabled="true">
</script>

B. Using API

Pass the enableGATracking parameter as true when initializing the Chargebee instance.

var chargebeeInstance = Chargebee.init({
site: "your-chargebee-subdomain",
enableGATracking: true
});

See also

The list of events passed to GA using the built-in integration.

Limitations of built-in GA integration

  • Built-in GA support is limited to checkout and portal pages. Modal-type action pages, such as Pay Now or Extend Subscription, are not supported.
  • If checkout or portal is launched via Chargebee emails (e.g., accept quote email or cart abandonment notification), built-in tracking will not work because Chargebee JS is not loaded.
  • If checkout or portal is opened in a new tab/window, GA integration will not work because Chargebee JS is not loaded.

Custom GA Integration

To address the limitations of built-in GA integration, set up GA event tracking using Chargebee JS callbacks.

Refer to the following pages for guidance:

You can combine customized event tracking with built-in tracking to extend functionality. For example, track successful checkouts by passing information to your site via query parameters in the redirect URL in your plans.

Warning

Avoid duplicate tracking If you implement Checkout success tracking on the plan redirect pages, you must not use built-in GA tracking as it would lead to duplication of checkout success events.

Note:

Testing the GA tag:
Test your GA tag using real-time reports. Note that non-real-time reports may take 24 to 48 hours to process.

Track Chargebee Checkout and Portal Events

Events passed to GTM/GA

The table below lists the events fired when the GA/GTM integration enabled:

Event Category
Event Action
Triggered When

ecommerce

Note:

Only triggered for Checkout and not for Portal

begin_checkoutThe first screen of checkout appears showing the cart.
engagementleadA subscription has been created with a trial period and no payment has been made. Additionally, this event is triggered in lieu of the purchase event if the domain where the checkout is invoked has not been .
cb-checkout
cart_screenThe first screen of checkout appears showing the cart.
check_user_screenUsed to verify the status or display of a user's screen or interface.
otp_authenticationThe screen for OTP authentication appears.
add_account_infoThe screen for entering the account details of the customer appears.
add_billing_addressThe screen for entering the billing address appears.
add_payment_methodThe screen for entering the payment method details appears.
add_subscription_cf_infoThe screen for entering any custom fields is shown.
review_screenThe summary screen for the sign-up is shown.
edit_order_screenThe order is edited.
edit_account_infoThe account information edit screen is shown.
edit_subscription_cf_infoThe custom field edit screen is displayed.
edit_payment_methodThe payment method edit screen appears.
edit_billing_addressThe screen for editing the billing address appears.
edit_shipping_addressThe shipping address entry screen appears. Also when the edit screen for the shipping address appears.
thankyou_screenThe final screen appears that prompts the user to close the window or redirects them to the redirect URL. Learn more about redirect URL while creating plans
cb-portalloginThe login screen appears.
homeThe Manage Subscriptions screen appears.
sub_detailsThe subscription details page is displayed.
portal_edit_subscription_cfA custom field edit screen is displayed.
edit_subscriptionThe change subscription screen is displayed.
add_addonsThe screen for adding addons to a subscription is displayed.
estimate_display_screenThe new order estimate screen is displayed.
portal_payment_methodsThe payment method lists screen is viewed.
portal_choose_payment_methodChoose payment method screen is displayed.
portal_view_payment_methodA particular payment method is viewed.
account_detailsThe details of the customer account are displayed.
portal_edit_accountThe edit account screen is displayed.
portal_addressThe billing/shipping address screen is displayed.
portal_edit_billing_addressThe billing address edit screen is displayed.
portal_edit_shipping_addressThe shipping address edit screen is displayed.
sub_cancelThe subscription cancel screen is displayed.

Purchase Event Parameters

This table lists the additional parameters passed as part of the purchase event:

Parameter
Description
transaction_idThe unique id generated by Chargebee for the checkout or portal session.
valueThe invoice total. This is the invoiced amount after discounts and taxes.
currencyWhen sending a UA event to a GA4 property, this currency value will be used for the GA4 items[].currency parameter.
taxTotal tax amount for this invoice.
items[]Array of products (plan and addons) ordered via Checkout.

Each array element for items[] is composed of the following:

Parameter
Description
items[].item_idThe id of the plan or addon.
items[].item_nameName of the plan or addon.
items[].item_list_nameAlways set to Chargebee checkout.
items[].item_categoryThe category of the item.
Either plan or addon depending on the product type.
items[].priceThe value depends on the pricing model of the plan/addon.
Here's how:
For per unit pricing model: the unit price of the plan or addon is set as the parameter value.
For flat fee: the catalog price for the plan or addon is set here.
For volume: the unit price of the tier the quantity falls under is set.
For tiered and stairstep: the average unit price of the plan or addon, determined as (catalog price รท quantity) is set.
items[].quantityThe quantity of the product purchased. It is set to 1 when the pricing model is a flat fee.

Add GA4 to a Site with Universal Analytics(UA)

Add GA4 to your existing UA setup to enhance the tracking and analytical capabilities of your website.

Note:

  • The Google setup Assistant Wizard does NOT change or modify your UA account.
  • It also does not backfill your new GA4 property with historical data.
  • Your GA4 property will only collect data going from the point where you set up the integration.

Prerequisite

You should have at least an Edit role for your GA account.

Information

If you use Google's analytics.js on your site, then ecommerce events will not be sent by the built-in GA integration. You must have gtag.js instead.

Steps to Migrate

Follow the below steps to add GA4 to a site with UA.

  1. In the UA property interface, click Admin.

  2. Under the property column, select the property that you'd like to migrate and click GA4 setup assistant. If you're doing this for the first time, you can either create a new GA4 Analytics property or connect your existing UA property to the GA4 property.

  3. Click Create property.

Learn more about adding a Google Analytics 4 property (to a site that already has Analytics).

How to get GA4 Measurement ID

You can use the Measurement ID to send data to a specific web data stream.

Follow the steps below to get your GA4 Measurement ID.

  1. Login to your GA4 analytics account.

  2. Navigate to the Admin section.

  3. Under the property section, Click Data streams.

  4. Select the data stream that you wish to track(likely to be your website). Then in the upper right corner, you can see your measurement ID. Learn more about G-ID.

  5. Click View tag instructions > Install manually and replace the existing GA script with this one.

Dual Tagging for Google Analytics

If you wish to track both UA and GA4 properties, then update the existing script of your analyitcs to add the new Google tag('G-XXXXXXXXXX') on each page of your website from the JavaScript snippet for your account along with the existing script for your website.

Example:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXX-X"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-XXXXXXXXX-X');
  gtag('config', 'G-XXXXXXXXXX');
</script>

How to Migrate UA Goals to GA4 Conversions

  1. Under GA4 property Click Setup Assistant.

  2. In the Setup Assistant, scroll down to Property Settings.

  3. Select Setup Conversions.

  4. Click > Actions Import from Universal Analytics. Note that, this option will appear if you are already connected to your UA ID and you have Goals set up under UA property.

Learn more about setting up conversions.

Analyze Data in GA4

After you have configured GA4 tracking for Chargebee Checkout and Portal, you can analyze the data in your GA4 account. You can view reports related to customer behavior, subscription trends, and revenue metrics, among others.

Was this article helpful?