问题
I have created a widget that is being hosted on a number of websites. I originally implemented the code using only jquery and JSONP to buid the widget. Upon implementing the widget on live webiste though we had the unfortunate experience of that other widgets which were on the site already had really poor javascript in them which killed our widget, so to cut a long story short I have created a second version which works using an IFrame. I have read up on the google analytics site that you can track usage in an IFrame fairly easily, but is there any way that I could track the usage of the original, iframeless version using Google Analytics. I could of course simply have an app on my side which counts the number of time the webservice I'm using to render the widget is called, and count the number of referrals on my site, but this seams like re-inventing the wheel when we already have Google Ananlytics to do this.
回答1:
I don't think it's reinventing the wheel since Google Analytics is not designed to do this.
The advantage of having an iframe is that the content of the iframe is on your site, and thus under your control. With your plugin on the wild everything you do is shared with the global page namespace and in the same manner the other extension killed yours, your extension could have killed others.
If you implement analytics on your extension you could be impacting the site very heavily if it also uses Google Analytics.
Multiple trackers on a single page is tricky in Analytics. It's possible but not very well supported and not recommended by Google.
The problem happens when you have conflicting Google Analytics settings with the other trackers on the page. Since you're sharing the same cookies both tracker configurations must be compatible. eg:
If one uses _setAllowHash
and the other does not the cookies will be reset for each time a pageview is fired, possibly breaking both implementations pretty badly.
So if you have other means to track your extension go for it. Try to use Google Analytics only on your domain, so you're free to go if you're doing it inside your iframe, otherwise try to avoid it.
If you can update the other extensions that are out there, why not just replace it with the iframe versions of it?
来源:https://stackoverflow.com/questions/10481659/track-number-of-impressions-of-a-widget-running-on-a-remote-website