我想使用 Google 分析跟踪多个域。详细地说,我有一个在花式框中打开的预订表格。此预订表单作为 iFrame 从另一个域(预订工具提供商)加载。这就是我打开fancybox的方式:
<script type="text/javascript">
$(function(){
$("#fancylink").fancybox({
'type' : 'iframe',
'width' : 700,
'height' : 450,
'autoScale' : false
});
$("#fancylink").trigger('click');
});
</script>
<a href="https://booking.tool.com/path/CODE?languageCode=en#http://www.maindomain.com/offers/booking.html" target="_blank" id="fancylink">Booking</a>
现在应该在 Google Analytics 中跟踪预订。我读了这篇关于跟踪 iFrame 的文章。
在标题中我有这个:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1234567-1']);
_gaq.push(['_trackPageview']);
_gaq.push(['_trackPageLoadTime']);
_gaq.push(['_setDomainName', 'maindomain.com']);
_gaq.push(['_setAllowLinker', true]);
(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>
在正文中,我有这段代码:
<script type="text/javascript">
_gaq.push(function() {
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('fancybox-frame');
if(iframe){
iframe.src = pageTracker._getLinkerUrl('https://booking.tool.com/path/CODE?languageCode=en');
}
});
</script>
现在我得到了跟踪不起作用的信息。目前,Google Analytics(分析)中不显示任何预订(只有未内置此类代码的旧购买)。目标是查看购买的金额,哪些文章等等。如何才能做到这一点?根据预订工具供应商的说法,一切都是为 Google Analytics 设置的。所以问题应该在我这边。
我的问题:
外观应该如何getLinkerUrl
?应该是:
- https://booking.tool.com(其他域)
- https://booking.tool.com/path/CODE?languageCode=en(目前使用的网址)
- https://booking.tool.com/path/CODE?languageCode=en#http://www.maindomain.com/offers/booking.html(iFrame URL)
第二张贴代码在正文中的位置是否正确?它应该在标题中吗?它适用于fancybox吗?我做错了什么?
编辑:
iFrame 中第一步的 Google 代码:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-7654321-1'],
['_setDomainName', 'tool.com'],
['_setAllowLinker', true],
['_trackPageview', '/booking/CheckAvailability']
,
['b._setAccount', 'UA-424242-11'],
['b._setDomainName', 'tool.com'],
['b._setAllowLinker', true],
['b._setCustomVar', 1, 'HotelID', 'SOME_ID', 3 ],
['b._setCustomVar', 2, 'PageName', 'CheckAvailability', 3 ],
['b._setCustomVar', 3, 'searchId', '', 3 ],
['b._trackPageview', '/booking/CheckAvailability']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
iFrame 中最后一步的 Google 代码:
var _gaq = _gaq || [];
_gaq.push(
['_setAccount', 'UA-7654321-1'],
['_setDomainName', 'tool.com'],
['_setAllowLinker', true],
['_trackPageview', '/booking/BookingConfirmation'],
['_addTrans',
'xyzabc', // order ID - required = reservationNumber
'Shop', // affiliation or store name
'800.00', // total - required = totalPrice
'0', // tax (always 0 - we don't model that)
'0', // shipping (always 0 - we don't model that)
'Test', // guest city
'', // state or province
'DE' // guest country
],
['_addItem',
'xyzabc', // order ID - required = reservationNumber
'W3 - Wohnstudio III', // SKU/code - required = room code + room name
'RateCode: SOME_PACKAGE_CODE, PromotionCode: ', // product name = rate code + promotioncode
'Adults: 2, '
+'Children: 0', // category or variation = 3 adults, 2 children
'800.0', // unit price - required = price per night per room
'1' // quantity - required = room nights
],
['_trackTrans']
,
['b._setAccount', 'UA-424242-11'],
['b._setDomainName', 'tool.com'],
['b._setAllowLinker', true],
['b._setCustomVar', 1, 'HotelID', 'SOME_ID', 2 ],
['b._setCustomVar', 2, 'PageName', 'BookingConfirmation', 3 ],
['b._setCustomVar', 3, 'searchId', '', 3 ],
['b._trackPageview', '/booking/BookingConfirmation'],
['b._addTrans',
'xyzabc', // order ID - required = reservationNumber
'SOME_ID', // affiliation or store name
'800.00', // total - required = totalPrice
'0', // tax (always 0 - we don't model that)
'0', // shipping (always 0 - we don't model that)
'Test', // guest city
'', // state or province
'DE' // guest country
],
['b._addItem',
'abcxyz', // order ID - required = reservationNumber
'W3 - Wohnstudio III', // SKU/code - required = room code + room name
'RateCode: SOME_PACKAGE_CODE, PromotionCode: ', // product name = rate code + promotioncode
'Adults: 2, '
+'Children: 0', // category or variation = 3 adults, 2 children
'800.0', // unit price - required = price per night per room
'1' // quantity - required = room nights
],
['b._trackTrans']
);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
在最后一步,URL 更改为类似这样的内容
编辑2:
现在我做了这个
_gaq.push(function() {
alert('test');
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('fancybox-frame');
if(iframe){
iframe.src = pageTracker._getLinkerUrl('<?php echo $link ?>');
alert(iframe.src);
}
});
我得到一个像
https://booking.tool.com/path/CODE?languageCode=en&__utma=60254466.192665702.4731206331.1344939538.1394680734.162&__utmb=60254466.7.9.1349681089757&__utmc=60312227&__utmx=-&__utmz=60254466.4731206661.2.4.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)&__utmv=-&__utmk=518158905
如果没有第一个警报,我永远不会收到第二个警报。因此,我认为迈克的假设是正确的。我应该投入beforeLoad
什么?打开 iFrame 时,我没有看到 Firebug 出现任何错误。在 Google Analytics 中,我只能看到一页条目/toolprovider/BookingConfirmation
。
编辑3:
现在我使用以下代码:
$("#bookingLink").click(function() {
var url = this.href;
var pageTracker = _gat._getTrackerByName();
$('#fancylink').attr('href', pageTracker._getLinkerUrl(url));
$('#fancylink').trigger('click');
return false;
});
但是在_gaq.push
函数中他找不到 iFrame。即使我fancylink
直接点击也找不到iFrame。我也用这段代码试过
$('#fancylink').fancybox({
'type' : 'iframe',
'width' : 700,
'height' : 450,
'autoScale' : false,
'beforeLoad' : function() {
var url = $('bookingLink').attr('href');
var pageTracker = _gat._getTrackerByName();
$('#fancylink').attr('href', pageTracker._getLinkerUrl(url));
}
});