AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

2K members online now
2K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
Guide Me

Google Analytics basic tag not working, 307 Redirect from source, Angular 2

[ Edited ]
Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi, I'm trying to setup Google Analytics for an Angular 2 app and I can't get any data to show up.  I have the tag added to the head of out index.html file that wraps the router and is on every page.  

I just have the basic analytics tag:


(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;
            m.parentNode.insertBefore(a, m);
            console.log('vars: ' + i + s + o + g + r + a + m);
        })(window, document, 'script', '', 'ga');

        ga('create', 'UA-xxxxxxxxx-x', 'auto'); //the id is correct and has been checked over and over
        ga('send', 'pageview');

I have the admin config setup to be pointing to the correct site and have checked all the "did you mess up the setup" things to try listed in your help pages.


So I started investigating the network tab to see if I can see anything, and I see that when my app tries to get the analytics url it gets a 307 redirect and then gets a version of GA that is just empty functions.  When I go to the url on my browser I get the code I expect.

Imgur Link to Screenshots of Networking

(I know these screenshots are on localhost but I have also deployed this code and saw the exact same thing so I don't believe it is related to being on localhost)

1 Expert replyverified_user

Google Analytics basic tag not working, 307 Redirect from source, Angular 2

Top Contributor
# 2
Top Contributor

Hi Jordan, 


try this resource for Angular JS and GA (the 307 is normal BTW)

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

Google Analytics basic tag not working, 307 Redirect from source, Angular 2

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

I assume a 307 is normal, what I'm surprised with is the code that is being returned from the redirect.  The routing example code here is for Angular 1, I will probably use angartics2 when I get to actually mapping angular, at this point I'm just trying to get any data to show up in my Analytics real-time view.

I tried calling the ga function on window from the initialization component of my app and have gotten then same empty/non behavior.  The ga function in question (the one supplied by the redirect) does nothing.

//ga source
(function() {
var noopfn = function() {
var noopnullfn = function() {
return null;
var Tracker = function() {
var p = Tracker.prototype;
p.get = noopfn;
p.set = noopfn;
p.send = noopfn;
var gaName = window.GoogleAnalyticsObject || 'ga';
var ga = function() {
var len = arguments.length;
if ( len === 0 ) {
var f = arguments[len-1];
if ( typeof f !== 'object' || f === null || typeof f.hitCallback !== 'function' ) {
try {
} catch (ex) {
ga.create = function() {
return new Tracker();
ga.getByName = noopnullfn;
ga.getAll = function() {
return [];
ga.remove = noopfn;
window[gaName] = ga;