Question

My users can embed an iframe from my site on their sites. I have Piwik working well and it tracks each time the iframe is loaded, but I really need to know which website is loading it.

Is it possible to set the Referrer to the page that loaded the iframe? I'm using the js tracking API and all Piwik code is inside my iframe.

I was hoping I would be able to do something like this from within the iframe:

var _paq = _paq || []; 
_paq.push(["setReferrerUrl", document.referrer]); 
_paq.push(["trackPageView"]); 

Really I want my boss to be able to login to Piwik and see a list of external URL's that included our iframe code over the last day.

Was it helpful?

Solution

I solved this by using the tracking pixel inside our iframe:

(function() {
  var d=document, 
      i=d.createElement("img"), 
      b=d.getElementsByTagName("body")[0],
      r=d.referrer,   
      u="https://mysite.piwikpro.com/piwik.php?idsite=#{ENV['PIWIK_SITE_ID']}&rec=1&url=#{video_url(@project)}&urlref=";

  i.src=u+r;
  b.appendChild(i);
})();

I'm using JS to append the img tag to the body, so that I can set the urlref param to document.referrer. Now I am able to track which sites my iframe is being viewed on the most. Works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top