Skip to content

Track Meta Refreshes to external sites using GTM

Google Tag Manager is fine if you want to track standard outgoing links. But what if the link is contained in a Meta Refresh? And you only want to capture certain meta refreshes? This was my challenge the other day!

  1. Set up a new variable in GTM, call it something like Get Meta Refresh
  2. Variable type should be Custom Javascript, and that javascript is as follows:function getMetaContent() {
    var metas = document.getElementsByTagName(‘meta’);for (var i=0; i<metas.length; i++) {
    if (metas[i].getAttribute(“http-equiv”) == “refresh”) {
    return metas[i].getAttribute(“content”);
    }
    }return “”;
    }

    All we’re doing here is looking at the Metas within the code and saving it.

  3. Next we create a tag/trigger combination.The Trigger is fired when the Get Meta Refresh variable contains the desired URL or domain (and the page name also matches a desired URL); the tag simply creates an event called ‘Refresh to outgoing link’ or similar.

And voila, we’ve created meaningful Events when a page Meta Refreshes to a specified domain.

Leave a Reply