Where can I learn more about cross domain or third-party JavaScript?
May 6, 2010 3:08 PM   Subscribe

Where can I learn more about cross domain or third-party JavaScript?

For a current project, I'm writing a web bug/beacon. Basically, it's some JavaScript that a page owner (not me!) can add in to get some analytics for a particular scenario. The analytics and scripts run on my server and not the page owner's, so there are a variety of challenges having to do with third-party cookies, same origin policies, and so on.

It seems like these problems are encountered by anyone who writes any sort of third-party JavaScript. What's more, standard solutions (e.g., learn a library) don't really help me for some of the browser incompatibilities, since it's probably not realistic to require a JavaScript library on every page that analytics will run on (and it's generally not rich interaction).

My question is, where can I find the best practices for writing third-party JavaScript analytics scripts?

I'd like to know how best to do things like capture link clicks, form submissions, idle time, and so on, in a cross browser fashion. I've read some open source code on this topic (e.g., Piwik), but it sometimes seems incomplete and doesn't give the reasons for particular decisions.
posted by pbh to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
Facebook does this. For the cross-domain communication, see the explanation here: http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication

More general information on their platform is easy to find.
posted by mezamashii at 3:29 PM on May 6, 2010 [1 favorite]


It's really not correct to say that the script 'runs on your server.' If the page owner inserts a <script> on their page pointing to your code, then it's running in the context of their domain; it's only hosted on your server. From the perspective of your code, the page owner's site is the first party so you don't have to worry about any cross site restrictions or anything to read cookies or modify anchors to proxy clicks. The only time the restrictions matter is when you need to get the data out of the page owner's domain and report it back to your systems. For that you can simply use XmlHttpRequest with a GET method and your data encoded as parameters because there are no cross-site restrictions with GETs.
posted by Rhomboid at 1:40 AM on May 7, 2010


Sorry, I misspoke about XMLHttpRequest not being restricted for GETs. What I meant to say was that you can simply encode whatever data you want into a GET request and then have the browser make that GET, e.g. by creating an IMG element with that URL.
posted by Rhomboid at 1:46 AM on May 7, 2010


« Older How many hours of your workday do you actually...   |   Can/should I use a different ssh keypair for each... Newer »
This thread is closed to new comments.