Howard
Howard

Reputation: 101

Google Analytics not sending page views from iFrame on FireFox

We have authored a widget, intended to be used by our customers on their sites. The customer imports our widget by adding a script tag to a page on their site. Our script then creates an iframe (same origin as parent), and inside the iframe loads the remainder of our code base.

We would like to be able to use google analytics for tracking both outside and inside the iframe. We do this by first initializing GA outside the iframe (using custom ga object name + tracker), for the purpose of obtaining the ga generated clientId of the user. We then use postMessage to send this information inside our iframe,and from there go on to initialize ga within the iframe (different custom ga global name + tracker name).

This all works well in Chrome,IE,Safari,Mobile Safari. However in FireFox (v28), none of the page-views sent from inside the iframe appear to be getting picked up.

When inspecting, the ga object appears to be properly initialized, but nothing seems to be sent to google.

Any advice would be appreciated.

//myGa is the custom named ga global

            window.myGa('create', cfg.accountId, {
                'name'          : 'myga',
                'clientId'      : cfg.clientId,
                'storage'       : 'none',
                'cookieDomain'  : 'none'
            });
            window.myGa('myga.send', 'pageview', {
                'page'  : '/my/page',
                'title' : 'My Test Page'
            });

Upvotes: 1

Views: 856

Answers (1)

Howard
Howard

Reputation: 101

SOLVED:

The problem lie in the way we were creating our iframe. It was causing the checkProtocolTask to fail in analytics.js

Minified checkProtocolTask:

    function Oa() {
        var a = M[B][E];
        if ("http:" != a && "https:" != a) throw "abort";
    }

For Clarification:

    //M[B][E] replaces document.location.protocol

In most browsers this was coming up as "http:" and passing, but in FireFox it was coming up as "javascript:" and failing the test.

The solution was to override the task implementation using the ga 'set' method.

    window.myGa('myga.set', 'checkProtocolTask', function(){});

(replace myGa with 'ga' and myga.set with 'set' if you are not using custom names)

Applying this override solved the problem.

Upvotes: 2

Related Questions