Our documentation has moved!

You are currently viewing a legacy version of our help articles.
For the most up-to-date version, please use the new Chargify Help & Support Site.
Follow

Integrating Google Analytics with Chargify

Getting Started with Google Analytics and Chargify

There are two methods to configure Google Analytics for Chargify - choose which option best suits your needs and follow the step by step setup guide.

1. Basic Google Analytics Integration with Chargify

  • Integrate Google Analytics with your Chargify Public Signup Pages and/or your Chargify Receipt Pages.

2. Cross Domain Tracking, Goals, Conversion Rate Funnels, and Ecommerce Tracking

  • Cross Domain Tracking - Tracks customers from your website (eg: your "buy now" page), to Chargify's Public Signup Pages, to Chargify's Receipt Page or your website's Thank You Page.
  • Goals - Track Conversions on Chargify's Receipt Pages or your Thank You Page
  • Conversation Rate Funnels - The Google Analytics Funnel Visualization Report offers insight into your customers' behavior as they travel through your complete Sales Funnel (this includes your website and Chargify's pages).
  • Ecommerce Tracking - Allows you to measure the number of transactions and revenue that your website generates for new signups. 



Basic Google Analytics Integration with Chargify

Using this configuration, you will be able to integrate Google Analytics on Chargify's Public Signup Pages and/or Chargify's Receipt Pages.

1. Get Your Google Analytics Tracking ID

  1. In Google Analytics, click "Admin" on the top menu
  2. Under the PROPERTY column, click "Tracking Info", and then Click "Tracking Code"
  3. Your Tracking ID will appear as UA-XXXXXXX-Y. Below is an example Tracking ID, yours will be different.

    Example Tracking ID

2. Edit The Tracking Code and Put The Code in Chargify

In the Google Analytics Tracking Code below, replace the red text with your Tracking ID. Then, copy the code and paste it in your Chargify Javascript section by going to Settings Tab -> Public Page Default Settings -> Javascript. Put the code at the very bottom of your Javascript - this ensures that if anything is wrong, you do not disable any other Javascript you may have. If you already have similar Google Analytics code be sure to remove it. When you're done, save your changes. 

if ($('#self-service-page').length === 0) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXX-Y', 'auto'); ga('send', 'pageview');

Note: This code will function on your Chargify Public Pages and Receipt Pages. We have purposefully disabled it from functioning on Chargify Self-Service Pages. 

Tip: Do not copy the Tracking Code from inside your Google Analytics account, because we have modified the Tracking Code to assist with the integration. 

3. Test it in Real Time

  1. In Google Analytics, click "Reporting" on the top menu
  2. Click "Real-Time" and then click "Overview"
  3. Open one of your Chargify Public Signup Pages that has your Google Analytics Code
  4. In your Google Analytics account, you will see an active user appear (this may take up to a minute)
If you see an active user: You have successfully configured a Basic Google Analytics Integration with Chargify. 

If you do NOT see an active user: Something is incorrect with your configuration. Repeat this section and try again. Common errors include using an incorrect Tracking ID, having <script> tags in your code, or copy/pasting the Tracking Code directly from inside your Google Analytics account instead of using the modified Tracking Code listed in Step 2 above.

 

 

Cross Domain Tracking, Goals, Conversion Rate Funnels, and Ecommerce Tracking (Advanced)

Add Google Analytics Cross Domain Tracking, Goals, Conversion Rate Funnels, and Ecommerce Tracking to Chargify to increase your reporting capabilities. 

1. Configure Cross Domain Tracking

Use Google Analytics to track your visitors as they move from your website to Chargify.

Common User Flows for Cross Domain:

  • Your website -> Chargify's Public Signup Pages -> Chargify's Receipt Pages
  • Your website -> Chargify's Public Signup Pages -> Your Website's Thank You Page
  • Chargify's Public Signup Pages -> Your Website's Thank You Page 

1.1. Get your Google Analytics Tracking Code

  1. In Google Analytics, click "Admin" on the top menu
  2. Under the PROPERTY column, click "Tracking Info", and then Click "Tracking Code". 
  3. Your Tracking ID will appear as UA-XXXXXXX-Y. (Tip: This ID will be used in several future steps and it MUST be correctly used for your integration to work. In this article, we have color-coded it red, so you will know exactly where to use this Tracking ID in future steps.) Below is an example Tracking ID, yours will be different.

1.2. Create a New Property

Use the image below to guide you through this step:

  1. In Google Analytics, click "Admin" on the top menu
  2. Choose your proper ACCOUNT
  3. Click the dropdown menu under PROPERTY
  4. Click "Create new property" (Note: You must have Admin access in your Google Analytics account to create a new property.)
  5. Choose "Website"
  6. Enter "Chargify" as the website name
  7. Choose "https" and enter "www.chargify.com" (this purposely does *not* include your Chargify subdomain).
  8. Choose Industry Category - "Other"
  9. Choose your Reporting Time Zone
  10. Click "Get Tracking ID"
  11. You're done. You do NOT need to take any further steps with the new Tracking ID or Tracking Code that appears.

    If you need help, read Google's Documentation

 

2. Define a Goal and Create A Sales Funnel

  1. Inside Google Analytics, click "Admin" on the top menu
  2. Under the PROPERTY section, select the correct property that matches the UA-XXXXXXX-Y Tracking ID that you obtained in Step 1.1.
  3. Be sure your VIEW is set to "All Website Data". Then, under the VIEW column, click "Goals". 
  4. Click "New Goal"
  5. Under Goal setup, choose "Custom" and click "Continue"
  6. Name your goal
  7. Skip "Goal Slot ID"
  8. Under Type, choose "Destination"
  9. Click "Continue".

If you are using Chargify Receipt Pages, continue to section 2.1. If you are using your own Thank You Page on your website, continue to section 2.2

2.1. Chargify Receipt Pages

If you do not use your Chargify's Receipt Pages and instead you use your own Thank You Pages, skip to section 2.2.

  1. In the "Goal details" section, under "Destination", choose "Regular expression" (Regex) from the dropdown menu and enter the following Regex code:
    • \/h\/.*\/subscriptions\/.*\/show
  2. Leave Value set to OFF (this allows for Ecommerce Tracking in a later section)
  3. Turn Funnel ON
  4. Enter a Name for Step 1 of the funnel, and enter the Screen/Page. This page will be the first page in your funnel. If you only want to count conversion rates for customers who begin on this step of the funnel, check "required". All Screen/Page links must be written in Regular Expression. To make one of your URLs compatible with Regular Expression, place it inside parenthesis.

    This particular example below uses (/home.html) because our example "buy now" page is at www.mywebsite.com/home.html. You will need to convert your page(s) into the proper Regex by finding a unique string in your URL (such as /home.html) and converting it into Regex by placing it between parenthesis.



    Tip: Do *not* include your domain name. If your funnel step URL is "www.mywebsite.com/home.html", only write "(/home.html)".
  5. Enter any other steps of the funnel that occur prior to the Chargify Public Signup Page. Make sure each is in Regex form.
  6. Enter the Chargify Public Signup Page as the last funnel step using the following Regex. If you use the normal URLs use "(/subscribe/)". If you use legacy URLs use "(/subscriptions/)".
    (/subscribe/) or (/subscriptions/)
    Tip: Do not include the Chargify Receipt Page as the last funnel step. The last step should be the Chargify Public Signup Page, as you have already defined your Destination as the Chargify Receipt Page.
  7. (Optional) Click "Verify this Goal" - This will only test the Receipt Page conversion rate within the last 7 days. It does not include the funnel steps. 
  8. Click "Save"

2.2 Your own Thank You Page 

If you have already completed Step 2.1 and you do not use your own Thank You Pages, you can skip this section.

  1. In the "Goal details" section, under "Destination", choose "Regular expression" (Regex) from the dropdown menu and enter your Thank You Page Destination. For example, if your Thank You Page URL is "www.mywebsite.com/my-thank-you-page.html" you should enter "(/my-thank-you-page.html)". The parenthesis are needed to make your partial URL compatible with Regex.



  2. Leave Value set to OFF (this allows for Ecommerce Tracking in a later section)
  3. Turn Funnel ON
  4. Enter a Name for Step 1 of the funnel, and enter the Screen/Page. This page will be the first page in your funnel. If you only want to count conversion rates for customers who begin on this step of the funnel, check "required". All Screen/Page links must be written in Regular Expression. To make one of your URLs compatible with Regex, place it inside parenthesis.

    This particular example below uses (/home.html) because our example "buy now" page is at www.mywebsite.com/home.html. You will need to convert your page(s) into the proper Regex by finding a unique string in your URL (such as /home.html) and converting it into Regex by placing it between parenthesis.



    Tip: Do not include your domain name. If your funnel step URL is "www.mywebsite.com/home.html", only write "(/home.html)".
  5. Enter any other steps of the funnel that occur prior to the Chargify Public Signup Page. Make sure each is in Regex form.
  6. Enter the Chargify Public Signup Page as the last funnel step using the following Regex. If you use the normal URLs use "(/subscribe/)". If you use legacy URLs use "(/subscriptions/)".
  7. (/subscribe/) or (/subscriptions/)
    Tip: Do not include your Thank You Page as the last funnel step. The last step should be the Chargify Public Signup Page, as you have already defined your Destination as your Thank You Page.
  8. (Optional) Click "Verify this Goal" - This will only test your Thank You Page conversion rate within the last 7 days. It does not include the funnel steps.
  9. Click "Save"
     

3. Enable Ecommerce in Your Google Analytics Reports

  1. Inside Google Analytics, click "Admin" on the top menu
  2. Under the PROPERTY section, select the correct property that matches the UA-XXXXXXX-Y Tracking ID that you obtained in Step 1.1.
  3. Be sure your VIEW is set to "All Website Data". Then, under the VIEW column, click "Ecommerce Settings". 
  4. Toggle Enable Ecommerce Status ON
  5. Leave Enable Related Products OFF
  6. Click "Next step"
  7. (Optional) Toggle Enhanced Ecommerce Settings ON. (In this article, we will opt to leave Enhanced Ecommerce Settings OFF)
  8. Click "Submit"

4. Edit The Ecommerce Tracking Code and Place the Code in Chargify or Your Website

4.1. Chargify Receipt Pages

If you do not use your Chargify's Receipt Pages and instead you use your own Thank You Pages, skip to section 4.2.

Copy the following code and paste it in your Chargify Javascript section by going to Settings Tab -> Public Page Default Settings -> Javascript. Put the code at the very bottom of your Javascript - this ensures that if anything is wrong, you do not disable any other Javascript you may have. If you already have similar Google Analytics code be sure to remove it. Be sure to edit the red text appropriately. Then, save your changes.

if ($('#self-service-page').length === 0) {
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true});
ga('require', 'linker');
ga('linker:autoLink', ['yourwebsite.com'] );

$(function() {
if ($('#hosted-payment-history').length !== 0) {

var transaction_id = $('#analytics-signup-payment-id').html();
var total_revenue = $('#analytics-signup-revenue').html();
var currency = $('#analytics-currency').html();
var product_id = $('#analytics-product-id').html();
var product_handle = $('#analytics-product-handle').html();

ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': transaction_id,
'affiliation': 'Your Company Name',
'revenue': total_revenue,
'currency': currency
});
ga('ecommerce:addItem', {
'id': transaction_id,
'name': product_handle,
'sku': product_id,
'category': product_handle,
'price': total_revenue,
'quantity': '1',
'currency': currency
});
ga('ecommerce:send');
}
});
ga('send', 'pageview');
}

If you do not use your own Thank You Pages, skip to section 4.3.

4.2. Your own Thank You Page

If you have already completed Step 4.1 and you do not use your own Thank You Pages, you can skip to section 4.3.

1. Insert your Redirect URL and Return Parameters in Chargify.

  • In Chargify, go to the Setup Tab
  • Click "Public Signup Pages"
  • Click "Edit" on a Product
  • Enter your full thank you page URL under "Return URL after successful signup" (eg: http://www.mywebsite.com/my-thank-you-page.html)
  • Copy/paste the following snippet of code under "Return Parameters"
    transaction_id={signup_payment_id}&revenue={signup_revenue}&name={product_handle}&sku={product_id}
  • Save changes
  • Repeat this step for each relevant Product in Chargify

2. Place the following code just before the </head> tag in your website's Thank You Page. If you already similar Google Analytics code, be sure to remove it. Be sure to edit the red text appropriately.

<script>
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

var transaction_id = getUrlVars()["transaction_id"];
var revenue = getUrlVars()["revenue"];
var name = getUrlVars()["name"];
var sku = getUrlVars()["sku"];

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXX-Y', 'auto', {'allowLinker': true}); ga('require', 'linker'); ga('linker:autoLink', ['chargify.com'] ); ga('require', 'ecommerce'); ga('ecommerce:addTransaction', { 'id': transaction_id, 'affiliation': 'My Company Name', 'revenue': revenue, 'currency': 'USD' }); ga('ecommerce:addItem', { 'id': transaction_id, 'name': name, 'sku': sku,
'category': name,
'price': revenue,
'quantity': '1',
'currency': 'USD'
});
ga('ecommerce:send');
ga('send', 'pageview'); </script>

4.3. Add Google Analytics Tracking Code to Any Other Pages (if necessary)

If you have other pages in your Sales Funnel that do not directly link to Chargify and are not your Thank You page, put the typical Google Analytics Tracking Code in the relevant pages on your website.

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXX-Y', 'auto'); ga('send', 'pageview');
</script>

5. Testing your Integration

There are several methods to verify your configuration is correct. 

5.1. Verify your Goals

  • In Google Analytics, click "Reporting"
  • Click "Real-Time" and then click "Conversions"
  • Perform a successful conversion by completing your Sales Funnel Process
  • Under "Active Users" or "Goal Hits (Last 30 min)", you should see your Goal Hits
  • This will confirm you have configured goals correctly.
  • Note: This does not confirm you have configured your Sales Funnel correctly

5.2. Verify your Sales Funnel

  • In Google Analytics, click "Reporting"
  • Click "Conversions" -> "Goals" -> "Funnel Visualization"
  • Perform a successful conversion by completing your Sales Funnel Process (if necessary)
  • Note: The Funnel Visualization chart can take up to 24 hours to populate data. Data may populate in pieces, so there may be temporary discrepancies as the data loads.
  • Tip: Make sure you are viewing the correct Goal

Example Funnel Visualization Report

5.3. Verify Cross Domain Tracking

  • View your Funnel Visualization report from Step 5.2. If you can see a successful conversion of a user passing through your website to Chargify (and, if applicable, back to your Thank You page), then you have successfully configured Cross Domain. 
  • (Optional) View your Audience User Flow Report by going to "Reporting" -> "Audience" -> "User Flow". This data takes approximately 24 hours to populate. See image below:

5.4. Verify your Ecommerce Tracking

  • In Google Analytics, click "Reporting"
  • Click "Conversions" -> "Ecommerce" -> "Overview"
  • Perform a successful conversion by completing your Sales Funnel Process (if necessary)
  • Note: Ecommerce tends to populate on a delay (10-15 minutes), and sometimes data takes longer to load. Data may populate in pieces, so there may be temporary discrepancies as the data loads.

Example Ecommerce Tracking Report

Need help?

Was this article helpful?
2 out of 2 found this helpful
Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Ivan Zhou

    This is a great article for ecommerce tracking. But do you have any information for Enhanced Ecommerce? It seems that you can load one or the other.

Please sign in to leave a comment.
Powered by Zendesk