我们在主网站上销售产品,用户点击“立即购买”按钮转到另一个域,其中购物车在iframe中提供。正确跟踪跟踪,但Google Analytics中的所有目标网页都会报告,就像用户登陆iframe源页面一样。
primarydomain.com/index.html跟踪代码:
<script type="text/javascript">
function trackOutboundLink(link, category, action) {
try {
_gaq.push(['_trackEvent', category , action]);
} catch(err){}
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
var _gaq = _gaq || [];
var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'UA-ourtrackingcodehere']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(["_setAllowLinker", true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
买入链接:
<a href="https://inc.shoppingcartdomain.com/page/" onclick="_gaq.push(['_link', this.href]); return false;">
shoppingcartdomain.com/purchase.html跟踪代码:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_require', 'inpage_linkid', pluginUrl]);
_gaq.push(['_setAccount', 'ourtrackingcode']); _gaq.push(['_setDomainName', 'none']); _gaq.push(['_setAllowLinker', true]); _gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s); })();
_gaq.push(function() {
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('apiframe');
iframe.src = pageTracker._getLinkerUrl(iframe.src);
});
</script>
页面上的iframe代码:
<iframe id="apiframe" src="https://inc.shoppingcartdomain.com/page/eDirect" width="100%" height="800" allowtransparency="true" frameborder="0" scrollbars=0><p>Your browser does not support iframes.</p></iframe>
shoppingcartdomain.com iframe源码跟踪代码:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'vendortrackingcode']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_setSessionCookieTimeout', 3600000]);
_gaq.push(['_trackPageview']); _gaq.push(['sec._setAccount', 'ourtrackingcode']);
_gaq.push(['sec._setDomainName', 'none']);
_gaq.push(['sec._setAllowLinker', true]);
_gaq.push(['sec._trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
要明确的是,除了着陆页之外,所有内容都正确跟踪(交易ID,金额,产品,来源,广告系列等)。它们都出现在购物车的iframe页面上。