Using Analytics.js:

    (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-1234567-1', 'auto');
    ga('send', 'pageview');

Given a second account UA-ZZZZZZZ-X, how would I push a page view event to this account?

I've tried just adding:

ga('create', 'UA-ZZZZZZZ-X', 'auto');
ga('send', 'pageview');

And the end, but it doesn't appear to be logging the views. In the old version you would do:

_gaq.push( ['app._setAccount', "UA-ZZZZZZZ-X" ] );
_gaq.push( ['app._trackPageview' ] );

But can't seem to get it working with analytics.js!


If you are using multiple trackers, then you need to name your trackers (or at least one of the two, but better to name both so there's no ambiguity).

Much like the Classic (_gaq) code you've posted, you would do the same with the Universal trackers and provide the name along with the method:

// tracker 1 named "someName"
ga('create', 'UA-ZZZZZZZ-X', 'auto', 'someName');
ga('someName.send', 'pageview')

// tracker 2 named "anotherName"
ga('create', 'UA-ZZZZZZZ-Y', 'auto', 'anotherName');
ga('anotherName.send', 'pageview')
| improve this answer | |
  • Brilliant, works perfectly! – Tom Gullen Apr 11 '16 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.