Reputation: 1618
My client's site is setup with a GA tag that's sending info to UA-XXXXXXXX-Y. They're going to add some PDF links which are hosted on another site (site B) they own. They want to track the PDF downloads in site B's analytics - another property of the same account: UA-XXXXXXXX-Z. Is there a way to achieve this?
Both site's are Wordpress.
If there's a way to get some backend code running that detects when someone hits a PDF url, I'm open to trying that. Wasn't able to get this approach to work myself.
Upvotes: 0
Views: 55
Reputation: 2040
You could try:
$("a").click(function(){
if ($(this).attr('href').includes('.pdf')) {
ga('send','pageview',$(this).attr('href'));
}
return true;
});
You would need to set ga
in this instance to be Site B's analytics.
POC:
$("a").click(function() {
if ($(this).attr('href').includes('.pdf')) {
alert('it\'s pdf time')
}
return true;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="mypdf.pdf" target="_blank">Click me</a>
<a href="myhtml.html" target="_blank">Click me too</a>
Upvotes: 0
Reputation: 931
You can put the PDF in an iframe and track the page it's inserted on.
As for downloads, a simple onclick="ga_event()"
event could help.
Upvotes: 0
Reputation: 5208
The only way to capture "direct" downloads of PDFs is to serve the pages up through a script. Example: www.mydomain.com/getpdf.php?pdf=mypdf
The script would then use the measurement protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/ to send a "hit" to GA for that download, then serve up the pdf for download.
The simplest is probably to not drive directly to the PDF, but a page with a link to it and track the link clicks as events.
Upvotes: 1