Browse by Topic

Setting Up Google Analytics

Google Analytics is a free analytics tool that helps you track visitors and conversions on your store. To set up Google Analytics, you will need to create and verify your Google account.

We've updated our Google Analytics integration to support Enhanced Ecommerce and Site Search. We've also made the setup easier and code free — all you need is your Google Analytics property ID.

Anyone using a Stencil or Blueprint theme can take advantage of our updated integration, but only those using Cornerstone or who have added Data Tags will get full functionality. See Requirements & Limitations to learn more.

 
 

Manual Setup

These steps will show you how to set up Google Analytics for Ecommerce Tracking and how to implement the code into your store manually. There are a few notes to be aware before continuing.

  • This implementation does not support Enhanced Ecommerce.
  • This implementation method can be used with either the Google's analytics.js or the Global Site Tag (gtag.js).
  • You must have a dedicated SSL as this feature does not work with the shared .mybigcommerce.com SSL certificate.
  • If using the manual setup, Enable DataTags should not be enabled.
 

Setting up Google Analytics

Ecommerce Tracking

1. In your Google Analytics account, go to AdminViewEcommerce Settings.

Ecommerce Settings highlighed in the View list

2. Under Enable Ecommerce, toggle the status to ON and leave Enhanced Ecommerce Settings set to OFF. Save your changes.

Enable Ecommerce set to the ON state and the Save button highlighted

3. Copy the following tracking code.

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

gtag('config', 'UA-xxxxxxxx-x')

function trackEcommerce() {
    function gaAddTrans(orderID, store, total, tax, shipping, city, state, country) {
        ga('ecommerce:addTransaction', {
            id: orderID,
            affiliation: store,
            revenue: total,
            tax: tax,
            shipping: shipping,
            city: city,
            state: state,
            country: country
        });
    }

    function gaAddItems(orderID, sku, product, variation, price, qty) {
        ga('ecommerce:addItem', {
            id: orderID,
            sku: sku,
            name: product,
            category: variation,
            price: price,
            quantity: qty
        });
    }

    function gaTrackTrans() {
        ga('ecommerce:send');
    }

    function gtagAddTrans(orderID, store, total, tax, shipping, city, state, country) {
        this.transaction = {
            transaction_id: orderID,
            affiliation: store,
            value: total,
            tax: tax,
            shipping: shipping,
            items: []
        };
    }

    function gtagAddItem(orderID, sku, product, variation, price, qty) {
        this.transaction.items.push({
            id: sku,
            name: product,
            category: variation,
            price: price,
            quantity: qty
        });
    }

    function gtagTrackTrans() {
        gtag('event', 'purchase', this.transaction);        
        this.transaction = null;
    }

    if (typeof gtag === 'function') {
        this._addTrans = gtagAddTrans;
        this._addItem = gtagAddItem;
        this._trackTrans = gtagTrackTrans;
    } else if (typeof ga === 'function') {
        this._addTrans = gaAddTrans;
        this._addItem = gaAddItems;
        this._trackTrans = gaTrackTrans;
    }
}

var pageTracker = new trackEcommerce();

</script>

4. Continue to Installing the Tracking Code.

 

Installing the Tracking Code

Once you have successfully generated the tracking code, it will need to be installed in your BigCommerce store.

1. In the BigCommerce control panel, go to Advanced SettingsWeb Analytics.

2. Check the box next to Google Analytics, then Save.

Google Analytics checkbox

3. Click the Google Analytics tab that appears at the top of the page.

Google Analytics tab

4. Paste the tracking code into the Tracking Code field and replace UA-xxxxxxxx-x with your Google Tracking Number.

Example installation using the manual method

5. Save your changes.

 
 

Excluding Referrals From Hosted Payment Gateways

To avoid transactions made through a hosted gateway such as PayPal appearing as referrals through Google Analytics, you will need to add the payment gateway to your Referral Exclusion List.

1. In your Google Analytics account, go to AdminPropertyTracking InfoReferral Exclusion List.

Tracking Info and Referral Exclusion List

2. Click Add Referral Exclusion.

Add Referral Exclusion

3. Enter the domain of your payment gateway (e.g. paypal.com) in the Domain field, then click Create to save your changes.

Domain field and Create button in the Referral Exlusion dashboard

Was this article helpful?