views:

542

answers:

1

We are going to launch JS based widgets which webmasters (any site) will be putting on their site by embedding a small code snippet like :

<iframe src="SOURCE_PATH" frameborder="0" width="300px" height="150px"  scrolling="no" id="cd_frame"></iframe>

Inside the widget there are three links and we need to track how many clicks are happening on them from the external sites where the widget is going to get used.

If I simply put the code which GA provides will that work? OR do I need to make any changes?

Thanks.

+4  A: 

you should be able to track from your iframe as it would appear to google analytics as a regular page. your issue would be knowing what iframe you were tracking. if you can pass a unique id via the iframe url then you should be able to add a custom parameter to track the different sites.

eg

<iframe src="SOURCE_PATH?uniquetrackingid=123" frameborder="0" width="300px" 
height="150px" scrolling="no" id="cd_frame"></iframe>

information about custom tracking codes can be found here http://www.google.com/support/analytics/bin/answer.py?hl=en&amp;answer=55585

Josh
Just to clarify here...You cannot track clicks inside an iframe from the parent window. This is considered cross-site scripting. You will have to have your GA code in the source of the actual iframe code in order to track clicks on links within the iframe. Josh sort of implied this when he mentioned passing a unique tracking parameter in the iframe src=".." it is the only way to pass data to the iframe, and the code in the iframe html can then look for it. You can grab it and put it in a custom variable or create goals based on it, etc...
Crayon Violent