Google Analytics Tracking Code

Please be aware that this article is related to Advanced Billing's integration with Google Analytics. You can learn more about this integration by checking out this help article: Google Analytics Overview.

Advanced Billing Receipt Pages

If you do not use your Advanced Billing’s receipt pages and instead you use your own thank you pages, skip to the next section, Your own Thank You page.

Copy the following code and paste it in your Advanced Billing custom JavaScript for your Public Signup Pages. 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 following text appropriately and save your changes.

  • Replace: UA-XXXXXXX-Y
  • Replace: Your Company Name
  • Replace: yourwebsite.com 
if ($('.public-signup-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 ($('.public-signup-page__success').length === 1) {

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 on adding Google Analytics tracking code to any other pages.

Your own Thank You page

If you have already completed the section on receipt pages and you do not use your own thank you pages, you can skip to section on Adding Google Analytics Tracking to other pages.

  1. Insert your redirect URL and return parameters in Advanced Billing.

    • In Advanced Billing, edit your individual Public Signup Page
    • 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 Advanced Billing
  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 any fields as needed, such as currency and company name.

<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', ['chargifypay.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>

Add Google Analytics Tracking Code to Any Other Pages

Please note, this step is not necessary.

If you have other pages in your sales funnel that do not directly link to Advanced Billing 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>
Was this article helpful?
0 out of 0 found this helpful