user2022284
user2022284

Reputation: 443

Google Tag Manager Rule to Identify Traffic Source

Is there a way to create a google tag manager rule ( via a macro ) which identifies the traffic source type? ( Like organic ?). Would like to create a tag which only fires if the source of traffic is organic. Possible?

Upvotes: 0

Views: 7046

Answers (2)

user3551128
user3551128

Reputation: 21

If your traffic arrives from tagged URLs (like from a campaign that you manually tag with the default GTM url tags) you can do this simply through the GTM interface.

I hope this helps.

Upvotes: 2

Eike Pierstorff
Eike Pierstorff

Reputation: 32770

Easiest way would be to extract the source (utmcsr) from the Google Analytics (__utmz) Cookie and fire an tag Manager event based on the value. Then create a rule based on that event.

I don't think it's possible solely from the tag manager interface.

(Updated to add) I've used the following code in the past and guess it'll still work (I'm afraid I can't give proper credit, I pinched that from some website).

/**
 Reads the Google utmz Cookie and returns he values as an array
 utmcsr = utm_source
 utmccn = utm_campaign
 utmcmd = utm_medium
 utmctr = utm_term
 utmcct = utm_content  */
function parseGACookie()  {
    var values = {};
    var cookie = readCookie("__utmz");
    if (cookie) {
        var z = cookie.split('.');
        if (z.length >= 4) {
            var y = z[4].split('|');
            for (i=0; i<y.length; i++) {
                var pair = y[i].split("=");
                values[pair[0]] = pair[1];
            }
        }
    }
    return values;
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

ga = parseGACookie();
if(ga['utmcsr'] == "cpc") {
    alert("Paid advertising");
}

Upvotes: 2

Related Questions