tingason
tingason

Reputation: 133

How to track only one domain in google analytics snippet

I´m having trouble figuring out how to track only one specific domain for my project in google analytics. I have a website that runs on two different domains (www.x1.com & www.x2.com)

In the following snippet I´m tracking traffic for both websites (that works) and I´m also trying to track only traffic for x2.com (does not work)

    (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-XXXXX-1', 'auto');
    ga('create', 'UA-XXXXX-2', 'auto', 'x2Tracker');

    ga('send', 'pageview');
    ga('x2Tracker.send', 'pageview');

I have two different accounts in my Google Analytics website. How can I track only traffic for my www.x2.com domain (but not both) ?

Upvotes: 0

Views: 1271

Answers (1)

J Brazier
J Brazier

Reputation: 884

You can apply a hostname filter to views of a Google Analytics account, so that it rejects traffic from www.x2.com (for example).

Bear in mind though that it believes x2.com and www.x2.com are different hostnames, so you should exclude them both. This is actually why I recommend an exclude filter, because you might have trouble stacking a pair of include filters.

This is done in Admin - View - Filters - New Filter

Upvotes: 1

Related Questions