Skip to content

Instantly share code, notes, and snippets.

@amontalenti
Last active August 29, 2015 13:56
Show Gist options
  • Save amontalenti/9079322 to your computer and use it in GitHub Desktop.
Save amontalenti/9079322 to your computer and use it in GitHub Desktop.
Implements IAB's SafeFrame option, as described in http://parse.ly/docs/integration/tracking/alternative.html#safeframe
<script>
/*
* $sf.ext.meta looks up metadata from parent window. Here's
* the relevant documentation from the SafeFrame standard:
*
* "Use to retrieve metadata about the SafeFrame position that
* was specified by the host. The host may specify additional
* metadata about this 3rd party content. The host specifies
* this metadata using the $sf.host.PosMeta class."
*
* The rest of this code does not depend on SafeFrame.
*/
function getParam(name) {
return $sf.ext.meta(name);
};
/*
* Called when the Parse.ly bootstrap code finishes loading.
*/
function handleParselyOnload() {
var url = getParam("url"),
urlref = getParam("urlref"),
title = getParam("title");
PARSELY.beacon.trackPageView({
url: url,
urlref: urlref,
title: title,
js: 1,
action_name: "Yahoo SafeFrame PV"
});
};
/*
* Configures Parse.ly bootstrap code for custom load-time behavior.
*/
PARSELY = {
// don't use default tracking, which will use wrong
// url, urlref, and title properties
autotrack: false,
// use our custom handler to fetch them from parent page
onload: handleParselyOnload
};
/*
* Standard DOM-free Parse.ly tag
*/
(function(d) {
var site = "eurosport.fr",
b = d.body,
e = d.createElement("div");
e.innerHTML = '<span id="parsely-cfg" data-parsely-site="'+site+'"></span>';
e.id = "parsely-root";
e.style.display = "none";
b.appendChild(e);
})(document);
(function(s, p, d) {
var h=d.location.protocol, i=p+"-"+s,
e=d.getElementById(i), r=d.getElementById(p+"-root"),
u=h==="https:"?"d1z2jf7jlzjs58.cloudfront.net"
:"static."+p+".com";
if (e) return;
e = d.createElement(s); e.id = i; e.async = true;
e.src = h+"//"+u+"/p.js"; r.appendChild(e);
})("script", "parsely", document);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment