Taoti Creative
Taoti Creative

Reputation: 1

Capturing PDF Download URL in Google Tag Manager (GTM) for Google Analytics 4 (GA4): Custom Dimension Not Populating

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:

  1. Trigger - on element where Click Classes contains external-processed

  2. Tag - Custom HTML with the above triggering:

function() {
 dataLayer.push({
   'event': 'pdfDownload',
   'PDF_URL': {{Click URL}}
  });
};
  1. Tag - GA4 Event with the above Event Name = pdfDownload and the above triggering. Here's the

GTM preview

  1. Custom dimension in GA4 where Dimension name is PDF URL, Scope is Event, and Event parameter is PDF_URL

The GA4 output below shows the custom dimension returning values of (not set)

GA4 Output

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

Answers (1)

darrelltw
darrelltw

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

Related Questions