≡ Menu

Update 2/18/2014:

As it turns out the logic I used in my test below has an issue due to using setTimeout to test whether the user’s browser had loaded the GA script successfully.  Phil Pearce commented and suggested following Andre Scholten’s method which avoids the use of setTimeout.  I’m happy to report that follow up tests indicated less than .5% (yes, 1/2 percent) of users failed to load the DoubleClick version of the Google Analytics script.  If you’ve updated your privacy policy and you’re ready to see some juicy demographic data about your users, I say go for it!

You’re about to lose visitor data.

That’s right, making the switch to the DoubleClick version (stats.g.doubleclick.net/dc.js) from the Google Analytics script (google-analytics.com/ga.js) will lead to lost data.  Why?  Ad blockers.    Reports of data lost range from 5% to as much as 22%.  In my own tests, I found that 6.87% of users that were able to load the google-analytics.com version of the script blocked the doubleclick.net version of the script.  In other words, if I make the switch to the DoubleClick version of the Google Analytics script, my visits will drop by about 6.87%UniqueVisitorsDoubleClickLost

OK, then why would I switch to the DoubleClick version?

Enabling the DoubleClick version of the Google Analytics script, allows you to see demographic data about users visiting your site.  This includes age, gender, as well as affinity categories (think music lovers, cooking enthusiasts, etc.).  This data can then be used to improve your own display advertising efforts and also remarket more effectively.  For the full rundown on these features, check out the official post from Google Analytics on reconnecting with your users.

How the heck is Google doing this?

When you visit sites that serve DoubleClick display advertising, a 3rd party cookie is dropped in the ‘doubleclick.net’ domain which follows you around from site to site.  DoubleClick can now build a profile about you based on sites you frequent and the ads you interact with.  When visitors come to your Google Analytics tagged site, Google Analytics drops a first party cookie that can only be read by your site (cookie dropped in ‘yoursite.com’).

Now for the fun part.  Before the change, Google Analytics was executing the script from google-analytics.com which meant it couldn’t ‘see’ that 3rd party doubleclick.net cookie.  When you make the switch to the DoubleClick version of the Google Analytics script, now Google can match the 1st party cookie from your site with the 3rd party cookie from DoubleClick and see the complete picture of what users did before they came to your site and what they did while they were on your site.  This, of course, opens the door for very effective remarketing which makes you (and Google) more money.

How can I find out how many users I’ll lose sight of?

I was hoping you would ask.  Fortunately, if you have Google Tag Manager, this test is quite easy.  First I need to lay out a few assumptions:

  1. You’ve implemented Google Tag Manager
  2. You’re firing Google Analytics exclusively via Google Tag Manager
  3. You’ve enabled a data layer for Google Tag Manager

What we’re going to do now is add a Custom HTML tag in Google Tag Manager which will load the DoubleClick version of the Google Analytics script and then check to see if it loaded.  If it’s loaded, then we’ll push a ‘success’ event to the data layer.  If it fails, we’ll push a ‘failed’ event to the data layer.  We’ll then add another Google Analytics tag which will fire the google-analytics.com version of the script when a success or failed event is pushed to the data layer.  The beauty of this is that we’re recording this event via the google-analytics.com version of the script, so our baseline is users that we know we can track.  Users that we record a ‘failed’ event for are the users we’ll no longer be able to track.

Here we go:

  1. Log into Google Tag Manager
  2. Select the appropriate tag container for the site(s) you want to test
  3. Create a new custom HTML tag with the contents shown below:
    <script>
    (function() {
      var ga = document.createElement('script');
      ga.type = 'text/javascript';
      ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    
      setTimeout(function(){
        if (typeof _gat == 'undefined') {
          //Record an event in GA via data layer
          dataLayer.push({
            'event':'doubleclickTest',
            'scriptLoad':'failed'});
        } else {
          dataLayer.push({
            'event':'doubleclickTest',
            'scriptLoad':'success'});
        }
      }, 1000);
    })();
    </script>
  4. Add a firing rule that fires on the home page of your site (e.g., url equals http://www.yoursite.com/)
  5. Add a Google Analytics tag
    1. Enter a descriptive name (I used ‘GA Monitor DoubleClick Load’)
    2. Enter your Web Property ID
    3. Set the Track Type to Event
    4. Set a Category of ‘DoubleclickTest’
    5. Click the ‘Add Macro’ button to the right of Action.
      1. Create a new Macro named ‘Script Load’
      2. Set the type to Data Layer Variable
      3. Set the Data Layer Variable Name to ‘scriptLoad’
      4. Click Save
    6. Verify the Action is now set to ‘{{scriptLoad}}’
    7. Click Add Rule to Fire Tag
      1. Enter a descriptive name (I used ‘Event equals doubleclickTest’)
      2. Under conditions, set {{event}} equals doubleclickTest
      3. Click Save
    8. Verify your new rule is under the ‘Firing Rules’ heading.
    9. (Updated 11/25/2013): Be sure to set the non-interaction flag to ‘TRUE’ otherwise you will have a pageview and an event for every visitor which will reduce your bounce rate to 0%.  Thanks to @AnalyticsNinja for catching this.
    10. You should see something like this:
      GoogleTagManagerDoubleClickAnalytics_2
    11. Click Save to save this tag
  6. Create a new version of your tag container
  7. Publish!
  8. Run the test until you have at least a week’s worth of data.
  9. In Google Analytics, create a custom report as follows:
    1. Metric = Unique Visitors
    2. Dimension = Event Action
    3. Filter: Include Event Category Exact DoubleclickTest
      Screen Shot 2013-11-23 at 12.03.15 PM
  10. Run the report, switch to the percentage view (pie chart icon on right) and you’ll see what percentage of unique visitors you’ll lose by switching to the Doubleclick version of Google Analytics.

Augh!@#$!#$! I’m losing xx.xx% of users?  What do I do?

KeepCalmAndMeasureOnIt’s up to you.  If you’re willing to forego the lost visitor data, then do it and reap the benefits of the DoubleClick insights and remarketing.  However, if you aren’t OK with this, you do still have options.  Since we can measure the amount of lost user data with the test above, we can use the same logic to inject the older google-analytics.com version of the Google Analytics script when the DoubleClick version of the script fails to load.  This, again, will require the use of a Custom HTML tag in Google Tag Manager that would look something like this:

<script>
var _gaq = _gaq || []; 
_gaq.push(['_setAccount', 'UA-XXXXXX-XX']); //Change your Profile ID here or map it to a Macro
_gaq.push(['_trackPageview']);
(function() { 
  var ga = document.createElement('script');
  ga.type = 'text/javascript'; 
  ga.async = true; 
  ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'; 
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

setTimeout(function(){ 
  if (typeof _gat == 'undefined') { 
    //DoubleClick script failed to load, load google-analytics.com version 
    var ga2 = document.createElement('script'); 
    ga2.type = 'text/javascript'; 
    ga2.async = true; 
    ga2.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s2 = document.getElementsByTagName('script')[0]; s2.parentNode.insertBefore(ga2, s2);
  } 
}, 1000); 
})(); 
</script>

Updated 11/25/2013: 

@AnalyticsNinja had a great suggestion on how you can avoid having to use a Custom HTML script to fire Google Analytics.  Instead, you would create two versions of the Google Analytics tags.  One would use the google-analytics.com version of the script and the other one would use the Display Advertising (doubleclick.net) version of the script.  You would then fire the appropriate script based on whether or not you were able to successfully load the DoubleClick version of the script.  You might do something like this in your custom HTML DoubleClick test script:

<script>
(function() {
  var ga = document.createElement('script');
  ga.type = 'text/javascript';
  ga.async = true;
  ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

  setTimeout(function(){
    if (typeof _gat == 'undefined') {
      dataLayer.push({
        'event':'doubleclickTest',
        'useScript':'googleAnalytics'});
    } else {
      dataLayer.push({
        'event':'doubleclickTest',
        'useScript':'doubleclick'});
    }
  }, 1000);
})();
</script>

Based on the above, you would then add a macro value for ‘useScript’ and rules that fired the google-analytics.com script when useScript equals googleAnalytics, and the DoubleClick version when useScript equals doubleclick.

I hope this article helps some of you decide whether to make the jump to DoubleClick’s Google Analytics tag.  If you’re having difficulties implementing this, please get in touch with me on here or Google+.

Happy measuring!

Additional Resources

  1. A simpler way to re-connect with your visitors (Google Analytics Blogspot)
  2. Doubleclick Remarketing and AdBlock: Our Solution to the dc.js Traffic Drop (Loves Data)
  3. Use of Ad Blocking is on the rise (Forbes)
{ 4 comments }

Single Page Applications are becoming more and more common as web developers adopt asynchronous technologies such as AJAX, Node.JS and Knockout. One of the challenges of adding a web analytics solution such as Google Analytics to a Single Page Application, is the browser location (site address) does not change as a user performs actions on the site. With Google Analytics, you can emulate a pageview by explicitly calling the _trackPageview function passing in a virtual page path (e.g., /home).

Now let’s say you want to implement Google Tag Manager to take advantage of the flexibility of being able to fire Google Analytics as well as some AdWords conversion tracking code as actions take place on your Single Page Application. Because the browser’s location bar doesn’t change, the traditional Google Analytics setup in Google Tag Manager won’t cut it. You need to leverage the event macro to tell Google Tag Manager that a ‘pageview’ has occurred. Let’s get to it.

In your Google Tag Manager container, add a new rule called ‘virtual pageview’ and set the event macro {{event}} equals ‘pageview’.  Don’t forget to click Save.

Now we’ll create a new Google Tag Manager macro that watches for a virtual url to appear in the data layer.  Note: If you aren’t sure what the data layer is or how to implement one, take a look at Justin Cutroni’s Data Layer post as well as the Google Tag Manager data layer help page.

  1. Enter a descriptive name for the macro such as ‘virtual url’
  2. Set the Macro Type to ‘Data Layer Variable’
  3. Set the Data Layer Variable Name to ‘virtualUrl’ (Note: this is the variable name you’ll need to specify in the Data Layer for the URL you want to track in Google Analytics)
  4. Click Save

It’s time to create our Google Analytics tag to fire when a new virtual pageview occurs.

  1. Enter a descriptive name for the Tag
  2. Choose a Tag Type of ‘Google Analytics’
  3. Enter your GA Profile ID
  4. Set the Track Type to ‘Page View’
  5. Expand Basic Configuration
  6. Check the Virtual Page Path box
  7. Click the +{{macro}} button
  8. Select the virtual url macro you created earlier
  9. Add a firing rule for the tag and choose the ‘virtual pageview’ rule created earlier
  10. Click Save

 

Now to enable the new tag along with the macro and firing rule, you’ll need to create a version of the tag container and publish it.  Now it’s time to populate the data layer with a virtual url when a user changes the view on our single page application.  This might look something like:

<html>
<head>
... 
<script>
  dataLayer = [];
</script>
<script>
function loadProductDetails(productIdentifier) {
dataLayer.push({
  'event':'pageview',
  'virtualUrl':'/product/'+productIdentifier 
});
// code to load product details and display to user
}
</script>
</head>
<body>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-3VLTP"
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-3VLTP');</script>
<!-- End Google Tag Manager -->
...
<a onclick="loadProductDetails('nexus7');">Nexus 7</a>
...
</body>
</html>

Now when a user clicks to view the the product details for a Nexus 7, the loadProductDetails function fires and pushes a new item into the data layer.  Google Tag Manager is watching the data layer and fires the ‘virtual pageview’ rule which triggers the Google Analytics Virtual Pageview tag passing in a virtual URL of ‘/product/nexus7’.  (‘nexus7’ is the productIdentifer parameter passed into the loadProductDetails function.)

Verify it’s working by viewing the Real-time Analytics reports for your GA profile.  You should see the ‘/product/nexus7’ pageview listed under  the ‘Top Active Pages’.

Have questions or comments?  Get in touch with me on Google+.

{ 10 comments }

One of the neat features of Google Tag Manager is the ability to fire a tag or some custom JavaScript to only a certain percentage of your users.  Why would you want to do this?   Let’s say you want to use a test app like Optimizely but don’t want to pay for one of the higher end packages due to the traffic volume on your site.  By only firing the Optimizely tag to a percentage of your users, you’ll save yourself some dough.  Another possible use case would be a survey pop-up to 5% of our users.

To sample our users with Google Tag Manager, we’ll need to add a new tag and then a rule that fires that tag a certain percentage of the time.  My steps below assume that you will be putting this tag into a test environment first and NOT straight to production.  You don’t want to have a JavaScript alert box popping up to 10% of your users on your revenue generating site.

Let’s get to it:

  1. Log into Google Tag Manager
  2. Select the test container you want to add the sampling tag to
  3. Click ‘New Tag’
  4. Enter a name such as ’10 percent alert’ for the tag
  5. Choose a tag type of ‘custom HTML tag’
  6. In the HTML box enter your custom JavaScript code: <script>alert(‘tag fired!’);</script>
  7. Click ‘ + Add Rule to Fire Tag’
  8. Choose ‘Create new rule’
  9. Enter a rule name of ’10 percent sample’
  10. Under ‘specify the conditions’, choose ‘New Macro’
  11. Enter a macro name of ‘Random Number’
  12. Change the Macro Type to ‘Random Number’
  13. Click Save
  14. Change the ‘contains’ box to ‘ends with’
  15. Enter ‘9’ in the empty value box.  (This means any time the randomly generated number ends with a 9, the tag will fire.)
  16. Click ‘Save’ to close the rule dialog
  17. Click ‘Save’ to close the tag dialog
  18. If you have a version of your test container, you’ll need to publish a new container version and then publish it.  This pushes the newly added tag to the tag container.
  19. Test!  Go to a page with your tag container and refresh it a few times.  Eventually you’ll see the JavaScript alert that says ‘tag fired!’.

If you want to change the percentage, you just need to change the rule conditions in step 15 above (be sure to change the rule name as well).  For instance, if you want to sample 1% of your users, you would change the value ‘ends with’ to ’01’ which would only match when the random number ends with ’01’ (101, 1001, etc.).  It wouldn’t match when the random number ends with ’00’,’02’, ’99’, etc.

Connect with me on Google+

{ 11 comments }

Google Analytics just announced a set of new social reports to help marketers identify the value of traffic from social media sites such as Facebook and Twitter. As marketers, when faced with “What’s the ROI for Social?”, we often answer with “it’s the intangibles” or “it can’t be measured”. Now, with the addition of the concept of an ‘assisted social conversion’, we can put a dollar amount to that indirect social conversion.


(via Capturing The Value Of Social Media Using Google Analytics)

{ 0 comments }

Late last year, Google AdWords added another Ad Extension called the ‘Communication Extension’ to their growing list of ad extensions. The Communication Extension allows you, the AdWords advertiser, to include a simple email registration form right underneath your ad!

As you can see above, because I was signed in with my Google Account when I saw the ad, my e-mail address was pre-populated meaning signup was only a click away (this form also appears when not signed in, the email box is just empty). I expect this will be an incredibly effective tool for acquiring new customer leads. A few seconds after I clicked the ‘Subscribe to Newsletter’ button, I was sent a welcome email telling me what to expect for being a new subscriber with a variety of ways to convert:

OK, this is awesome, how do I get it?
To get access to the Communication Extension in your AdWords account, you’ll need to contact AdWords and request to join the beta program. An AdWords rep will contact you to get specific information about your site including where sign ups will go and reviewing the privacy policy in place on your site.

I’m looking forward to implementing this on more client sites so I can measure the effectiveness and write more about it! What do you think? Will you be contacting AdWords to get the new Communication extension?

{ 0 comments }

Twitter doesn’t allow multiple accounts on one email address… or do they? If you have Gmail, you can create additional twitter accounts by using aliases. To create an alias in Gmail, you simply add a plus sign (+) after your Gmail user name and add the alias before the @ symbol. For instance, if you receive email at: myname@gmail.com, you would create an alias by using: myname+somealias@gmail.com.

An added bonus to using an alias in Gmail is that you can filter messages that are sent to that alias. Let’s say I create a twitter account using an email address, myname+cooltwittername@gmail.com. I can then set up a filter in Gmail (Gear Icon > Mail Settings > Filters > Create New Filter) and perform a variety of actions on emails sent to my alias such as archiving (skip inbox) and applying a label. This way I can review the messages under this label that may not be as time sensitive as my main inbox.

Using email aliases in Gmail is also a great strategy for signing up for websites that you may not want to see emails from on a regular basis. You can create a Gmail alias like ‘myname+spam@gmail.com’ and create a filter that applies a label and skips the inbox for all messages sent to your alias. The only trick here is that some sites don’t allow the plus sign (+) in email addresses due to outdated/over-aggressive validation logic.

{ 0 comments }