Search code examples
google-analyticsuniversal-analytics

Google Analytics: Test event tracking with test profile


With Universal analytics, what are the best practices in sending/testing data to a test profile?

I've included the tracking snippet before the </head> and the following:

window['ga-disable-UA-XXXXXXXX-X'] = true;

ga('create', 'UA-XXXXXXXX-X', {
  'cookieDomain': 'none'
});

ga('send', 'pageview');   

Solution

  • I'll usually handle this by always keeping the same code in production vs staging (aka remove the ga-disable and cookieDomain lines of your code snippet). I then create 2-5 different views in Google Analytics and filter them as:

    • Default (include only production domains - eg: regex ^(www\.)?example\.com$)
    • Raw Data (no filters)
    • Test Site (inlude only test domains - eg: exact test.example.com)
    • Staging Site (include only test domains - eg: exact staging.example.com)
    • Admin Site (include only admin domain - eg: exact admin.example.com)

    Under Profile >> Filters there are predefined filters and custom filters. Use a predefined include Traffic to the Domain for all of the above.