Reputation: 1
I'm having issues capturing the URL of PDFs clicked on my website's resource page. PDF links open in new tabs/windows upon clicking. GA4 Enhanced Measurement Form Submits and Link Click events aren't firing for these clicks.
Below is the configuration that isn't working:
Trigger - on element where Click Classes contains external-processed
Tag - Custom HTML with the above triggering:
function() {
dataLayer.push({
'event': 'pdfDownload',
'PDF_URL': {{Click URL}}
});
};
Event Name = pdfDownload
and the above triggering. Here's theEvent parameter is PDF_URL
The GA4 output below shows the custom dimension returning values of (not set)
Given that the PDFs open in new tabs, what could be preventing the PDF URL from populating in GA4, and how can I resolve this?
I tried a lot of variations with the custom HTML tag code.
Upvotes: 0
Views: 149
Reputation: 2372
Looks like you are firing the JS in Tag has some issue.
The way you are doing is something similar in Custom JavaScript Variable
But in Custom Html Tag
. There is a difference
<script>
(function(){
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'pdfDownload',
'PDF_URL': {{Click URL}}
})
})()
</script>
Your code is
<script>
function() {
dataLayer.push({
'event': 'pdfDownload',
'PDF_URL': {{Click URL}}
});
};
</script>
That is still a js code. But only run in Custom JavaScript Variable
and it's better to have a return value there.
Upvotes: 0