Google Tag Manager for BigCommerce

Yes, it IS possible to use Google Tag Manager to implement Google Analytics on a BigCommerce site.

Before we dive in I want to thank one of my developers, Scott Rarden and also Anirudh from Google for their help.

And a huge thanks to Jeremy & the others on the GTM threads.  I’m very new to BigCommerce and the paths they forged were incredibly helpful in coming up with a solution.

Now for the gory details:

As Jeremy mentioned previously you will need to add a new Panel to every page that should include GTM.  The GTM Panel should be placed just after the opening <body> tag.

Create a new file /template/Panel/GoogleTagManagerTag.html

The file should contain the Google Tag Manager code for your site which will look similar to the one below:

 <!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-YOURCODE"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-YOURCODE');</script>
<!-- End Google Tag Manager -->

Make sure you use the GTM code that your receive from the GTM website.  Don’t copy/paste the example above.

Once the Panel is created it then needs to be included on every page of your site.

For either method below you will likely need to review all of the template files that a visitor is capable of viewing.

Option 1:

Add the new GTM panel to all of your publicly visible pages by hand. Depending on the design you’re using for your site this can be 55-60 (or more) pages.

Option 2:

If you already have a Panel appearing in the correct spot then we can add our GTM Panel to the existing Panel.

Review your template files.

Open each of the files in the top level of the /template folder and view them in a text editor.

Locate the opening <body> tag.

Determine if there is (or is not) a Panel immediately after the opening <body> tag on all pages.

  • If there IS a Panel immediately after the opening body tag on all pages then you can use Option 2.
  • If there is NOT a panel immediately after then you will need to edit the file and include the Panel by hand.

Option 1 Example:

<body id="home">
    <div class="page">
      %%Panel.Header%%
    %%Panel.HomeSlideShowJavaScript%%

Since there is no Panel immediately after the <body> tag one must be created.  The GTM tag should NEVER be placed inside of a <div> or other tag.  It must reside directly within the <body> tag.

<body id="home">
    %%Panel.GoogleTagManagerTag%%
    <div class="page">
      %%Panel.Header%%
    %%Panel.HomeSlideShowJavaScript%%

Option 2 Example:

<body id="home">
    %%Panel.DrawerMenu%%
    <div class="page">
      %%Panel.Header%%
    %%Panel.HomeSlideShowJavaScript%%

The %%Panel.DrawerMenu%% is in the correct location for the GTM tag.  As long as the %%Panel.DrawerMenu%% appears on all of the publicly visible pages we can simply add our GTM Panel to the existing Panel.

  • edit/customize the existing /template/Panels/DrawerMenu.html file
  • add %%Panel.GoogleTagManagerTag%% to the top of the file.

Before:

<div id="DrawerMenu">
    <div class="inner">
        %%Panel.SideCategoryList%%
        %%Panel.SideShopByBrand%%
        %%Panel.SideCategoryShopByPrice%%
        %%Panel.SideAdditionalInformation%%
        %%Panel.SideAccountNavigation%%
    </div>
</div>
%%Panel.DrawerMenuJavascript%%

After:

%%Panel.GoogleTagManagerTag%%
<div id="DrawerMenu">
    <div class="inner">
        %%Panel.SideCategoryList%%
        %%Panel.SideShopByBrand%%
        %%Panel.SideCategoryShopByPrice%%
        %%Panel.SideAdditionalInformation%%
        %%Panel.SideAccountNavigation%%
    </div>
</div>
%%Panel.DrawerMenuJavascript%%

If you make it through all of the above then Google Tag Manager should be appearing on all of your pages.

The next big hurdle is to accommodate Ecommerce Transaction reporting.

Note: The instructions below are for ‘standard’ Ecommerce tracking.  We’ll have to tackle Enhanced Ecommerce Reporting another day!

Ecommerce Transaction Tracking

In short the existing ‘traditional format’ GA Transaction code needs to be translated into the new ‘dataLayer’ syntax for GTM.  As Jeremy pointed out back on 07-23-2014 it would take some scripting to make this work.  The script below will do the job.

Note: WordPress tends to mess with single & double quote characters.  A text-only copy of the script is available here.

<script type="text/javascript">
var dataLayer = new Array();
// console.log(dataLayer);
function trackGTMEcommerce() {
    this._addTrans = addTrans;
    this._addItem = addItems;
    this._trackTrans = trackTrans;
}

var transaction = {};
transaction.transactionProducts = [];

function addTrans(orderID, store, total, tax, shipping, city, state, country) {
    transaction.transactionId = orderID;
    transaction.transactionAffiliation = store;
    transaction.transactionTotal = total;
    transaction.transactionTax = tax;
    transaction.transactionShipping = shipping;
    // console.log(11)
}


function addItems(orderID, sku, product, variation, price, quantity) {
    transaction.transactionProducts.push({
        'id': orderID,
            'sku': sku,
            'name': product,
            'category': variation,
            'price': price,
            'quantity': quantity
    });
    // console.log('a')
}

function trackTrans() {
    transaction.event = 'bcTransactionComplete';
    // console.log(transaction);
    dataLayer.push(transaction);
}

var pageTracker = new trackGTMEcommerce();
</script>

For an easy setup:

Go to Settings => Web Analytics and enable Google Analytics.
Then paste the script into the ‘Tracking Code’ box for Google Analytics

For a more precise setup:

This script really only needs to appear on the /finishorder.php page.
Thus you could put it into the <head> section of just that page.

Caveat: You will need to put something in the Google Analytics ‘Tracking Code’ box under Settings => Web Analytics in order for the Ecommerce data to appear.
A comment works fine.

IMPORTANT:

You will need to trigger the GA Transaction tag in GTM using a custom event.
In the example script above the event name is set on the line:

transaction.event = 'bcTransactionComplete';

You will need to configure GTM to fire the GA Transaction tag on the ‘bcTransactionComplete’ event.

Google AdWords Email Phishing Scam

Thanks to @aimclear for being quick to post the info on this scam. Here’s an email that I wrote to all of my AdWords clients based on the tweets that @aimclear posted with the text from the email he received. Feel free to copy and reuse for your clients.

————————————————————–

Dear Client,

I’ve heard from colleagues today that there is a phishing scam targeting Google AdWords account users. This scam is an email with the following (or similar) text:

" Dear Client, Your Google Adwords account has expired. You must renew it immediately or your account will be closed. If you intend to use this service in the future, you must take action at once!. To continue click here, login to your Google Adwords account . Thank you for using Google Adwords! Google Adwords Services DEP. COPYRIGHT Google Adwords Services 2009 (C) "

The email includes a link that will take you to a log in page that looks no different from the Google AdWords log in page you are familiar with. Please do not log into your account via this link. The URL is *not* on Google’s secure servers.

If you think that you’ve been a victim of the scam, please try to log into your account immediately via https://adwords.google.com and change your password. If you are unable to log in, please contact me as soon as possible and I will contact a Google representative on your behalf.

Thanks,
Sally Burke
————————————————————–

Revealing geographic AdWords performance statistics using Google Analytics

If you’re running an AdWords campaign that serves multiple countries, you may want to see how each country is performing individually. I came across this again recently when discussing AdWords performance with one of my e-commerce clients. In his campaign, he is running ads in both the US and Canada. “How is Canada performing compared to the US?”, we wondered.

As far as I can tell, AdWords Report Center does not have a method for seeing data per country. Their demographics reporting is limited to age and gender. Here’s my method for revealing the data using Google Analytics. Your AdWords account must be properly linked to your Google Analytics account for this to work.

1. Log into your Analytics account and in the Dashboard, select Visitors > Map Overlay.

From your Google Analytics Dashboard, select Map Overlay.

2. On the Map Overlay screen, select the country of interest, in my case that was Canada. You can drill as deep as you like here.

Select your country of interest.

3. In the Dimension selection drop-down, choose Campaign.

Choose Campaign in the Dimension drop-down

4. Now, you can see the productivity of your Campaign(s) in the geographic region that you selected.

AdWords Campaigns revealed.

Now you want to know what to do with this new data? Well, I hope it convinces you to segment all of your countries into separate campaigns. For this client, Canada’s conversion rate is 68% lower than the site average. I’ll be splitting out Canada into a separate campaign as soon as I finish this post and redistributing my spend. I’ll also be talking with my client about updating his site to include Canadian shipping rates and landing pages for Canadian customers.

For a hot tip on how to make doubly sure that Google is only serving your US targeted campaign to US customers, see Uber Affilliate’s article, “QuickTip Time : Adwords International Traffic

UPDATE 09/03/2008: Looks like Google AdWords finally decided that