Google Analytics: Tracking certain clicks coming from an Iframe Widget
Situation:
- There is a ecommerce platform myshop.com
- There is an affiliate partner that integrates a "mini shop" in an iframe with src=myshop.com/widget
- Within the widget, I can navigate through categories and browse them
- When clicking on a linked product, myshop.com/manufacturer/product-x opens in a new window
Complication:
- The payment model between the affiliate partners is based on CPC, but restricted to clicks on products (which imply an "escape from the iframe" as described above)
Question:
- How to track these clicks from the perspective of myshop.com 开发者_Python百科so that they are aggregated somewhere in Google Analytics?
The most secure way to achieve this is to ask the partners to include a query parameter with some kind of identification when including the iframe. You need this because you can't access the outer window in order to get partner url from within the iframe. So the partners would be inserting the following code:
<iframe src="myshop.com/widget?partner=StoreXYZ" />
Now from inside the iframe just grab that query parameter and send to analytics along with the product Clicks. Try this. JQuery code.
$('.product').click(function(){
var product = $(this).text() || 'Unknown Product';
var partner = document.location.search;
try{
partner = partner.match(/partner=([^&]+)/)[1];
}except(e){
partner = 'None';
}
_gaq.push(['_trackEvent', 'PartnerClicks', partner, product]);
});
This is just an example. I tried to get the product name and partner. And fire a Google Analytics Event when a product is clicked.
This will give you a nice report inside Content>Event Tracking. You can check clicks per partner or per product, and drilldown any one into the other.
Be warned that Google Analytics impose some limitations and if you have too many products or partners you can reach those limits.
The limit is 50.000 unique values per report for the combination partner+product.
So if your number of partner multiplied by the number of products exceeds 50k you may consider dropping the product part (just omit that last parameter of _trackEvent).
If your number of partners alone exceeds the 50k limit, than you'll have to register those interactions at some other tool, instead of Google Analytics
精彩评论