Skip to content

Add ability to pass a referrer to Snowplow from an IFRAME #1

@alexanderdean

Description

@alexanderdean

Original issue: snowplow/snowplow#265
Author: https://github.com/joshspivey

There needs to be a way to pass a referrer through a iframe. Lets say you have iframe hosted at A and and host B loads the iframe you cant access the referrer it completely errors out omniture gives you the ability to set this. Now the best way to pass the referrer through is a query string on the iframe this is the less error prone method with less code and most cross browser.

Example:

<iframe src="//:locationA? referrer =http://somesite.com"></iframe> 

A solution in the Snowplow JavaScript Tracker is:

 window.qs = (function(a) {
    if (a == "") return {};
    var b = {};
    for (var i = 0; i < a.length; ++i)
    {
        var p=a[i].split('=');
        if (p.length != 2) continue;
        b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
    }
    return b;
    })(window.location.search.substr(1).split('&'));


SnowPlow.getReferrer = function() {
    var a = "";
    if (window.qs["referrer"]) {
              a=window.qs["referrer"];
    } else {
        try {
            a = SnowPlow.windowAlias.top.document.referrer
        } catch (c) {
            if (SnowPlow.windowAlias.parent) {
                try {
                    a = SnowPlow.windowAlias.parent.document.referrer
                } catch (b) {
                    a = ""
                }
            }
        }
    }

Metadata

Metadata

Assignees

Labels

type:enhancementNew features or improvements to existing features.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions