Track documents download in your Web Applications | Google Tag Manager integration with AEM 6.5.5 SPA

Hello AEM folks after a long time. So Let’s get started with the topic in which we will track the download of any doc or pdf from your web application.
To track this we will use GTM and Google Analytics along with AEM codebase.

So GTM (Google Tag Manager) is a free service provided by Google. So we will create a container in GTM. You can go to https://tagmanager.google.com/?hl=en#/admin/accounts/create to create GTM container and give the container name and choose Target Platform as Web

GTM Container configuration

Now on your GTM dashboard, go to variables and add some click variables:

Now we will create Tags and Triggers to track the event. Now navigate to Tags option on GTM Dashboard and create a Event with following fields and values.
Select Tag Type as Google Analytics : Universal Analytics


Google Analytics Settings variable needs to be created using the tracking id from Google Analytics which can be obtained from going to Google Analytics dashboard and Admin. Then Tracking Info > Tracking Code. Copy the ID that looks like this UA-XXXXXX-XX and paste it to the Tracking ID field in GTM.

Now we will create a trigger which will be attached to this tag that we created above. Create a trigger of type Just Links.

Add the type of files you want to track. Once whole configuration is done then publish the tag created and go to Admin in GTM and open Install Google Tag Manager and copy paste the scripts in the head.html and the body.html of your project.

As I am using AEM SPA code setup so I pasted it in my body.html and customheaderlibs.html

After pasting the script snippet in code base and publishing the tags now once you click/download any pdf or doc it will track it as part of Google Analytics reports. You cam go to Google Analytics dashboard and go to Realtime and then Events, it would be logged there.

Comment or Follow my blogs for any query and solutions.

Thanks for Reading and Happy Coding!

Author:

I am Nikhil Kumar, AEM developer. Working on AEM since the start of my career. Created this blog to share my AEM knowledge and give back to the AEM Community. You can reach out to me on any query.

Leave a comment