<iframe src="about:blank" data-iframe-src="http://www.domainB.com"></iframe>
<noscript><iframe src="http://www.domainB.com"></iframe></noscript>
function() {
return function() {
dataLayer.push({
'event' : 'gaHitCallback'
});
return true;
}
}
function() {
var i = dataLayer.length,
gaLoaded = false,
domLoaded = false;
while(i--) {
if(dataLayer[i].event === 'gtm.dom') {
domLoaded = true;
}
if(dataLayer[i].event === 'gaHitCallback') {
gaLoaded = true;
}
}
return domLoaded && gaLoaded ? '1' : '0';
}
<script>
(function() {
var iframes = document.getElementsByTagName('iframe'),
i = iframes.length,
iframe, src, uaLinker, gaLinker, trackers;
//if universal analytics
if(typeof ga !== 'undefined' && typeof ga.getAll === 'function') {
trackers = ga.getAll();
if(trackers.length) {
uaLinker = new window.gaplugins.Linker(trackers[0]);
}
}
//if classic analytics
if(typeof _gat !== 'undefined' && typeof _gat._getTrackers === 'function') {
trackers = _gat._getTrackers();
if(trackers.length) {
gaLinker = trackers[0];
}
}
//now loop through all iframes, decorate the source url and remove the display none
while(i--) {
iframe = iframes[i];
if(iframe.src === 'about:blank' && iframe.getAttribute('data-iframe-src')) {
src=iframe.getAttribute('data-iframe-src');
if(uaLinker) {
src = uaLinker.decorate(src);
}
if(gaLinker) {
src = gaLinker._getLinkerUrl(src);
}
iframe.src=src;
}
}
}());
</script>