I'm looking to develop a Omniture "trouble" tag that will fire within Google Tag Manager. This tag should check to see whether the Omniture s.code on-page has fired a pageview. If it hasn't, send an Event to our GA account.
Ideally, it'd look like this (pseudocode follows):
<script>
window.onload=function(){if(OmniturePageViewHasFired == false){
ga('send','event','SCodeMissing','Page',window.location.href);
}}
</script>
Just checking to see whether the s.code is on page at all is a much easier task, but won't be as useful since it's possible for the code to be on page and not have fired. Any ideas? Also note that I do NOT have access to the s.code itself, so I can't set a variable with it that's then picked up by this script.
This is how I'd do it, based on how Adobe's DigitalPulse Debugger looks for it:
function OmniturePageViewHasFired() {
var i=document.images;
for (var c=0,l=i.length;c<l;c++) {
if ( (i[c].src.indexOf('/b/ss/')>=0)
&& (!i[c].src.match(/[&?]pe=/))
) return true;
}
for (var o in window) {
if ( (o.substring(0,4)=='s_i_')
&& (window[o].src)
&& (window[o].src.indexOf('/b/ss/')>=0)
&& (!window[o].src.match(/[&?]pe=/))
) return true;
}
return false;
}
//example:
if (OmniturePageViewHasFired() == false){
// no omn request detected
} else {
// found at least 1
}
Note 1: This will only return true if a page view (s.t
) request is made. It will not return true for click requests (s.tl
). If you want it to return true for any request, then remove the last &&..
in the 2 conditions.
Note 2: Officially Adobe thinks it is good enough to just look for /b/ss/
in the src
. Admittedly, in all my years of QA'ing Adobe Analytics (btw that's what it's called now, not Omniture), I've only seen a false positive from this like one or two times.
If this worries you, you can make the condition more specific by evaluating the domain of the src
for your implementation. This is unique to your implementation, which is why Adobe doesn't look for something more specific. Just look at a request on your page to get it.