'Linkedin tracking for single page app in Google Tag Manager
I'm trying to implement LinkedIn's insight tracking tag in Google Tag Manager on a single page React web application. Since there are no 'real' page reloads, the tag is only fired once. I have a dataLayer event that triggers on rerouting in the app, so I tried setting the tracking tag to fire on that event. The tag itself now fires multiple times but it does not track the new location.
What can I do to solve this?
Solution 1:[1]
It is not an official solution but you can add a custom HTML tag including this:
<script>
lintrk("track");
</script>
It will be triggered by History Change event.
Solution 2:[2]
You can fire Virtual pageviews on that particular dataLayer events.
What is a Virtual Pageview
Virtual Pageviewsrefers to sending the pageview hits to Google Analytics, without reloading the page. For the single page page app, virtual pageviews are good to track the sections.
Steps
- Determine a standard notation for virtual pageview like /vpv/section name
- On the Datalayer event, push the value of section name to the website section or something that can let you know which section the user is on.
- For reporting, you can now actually see how many views happened for that particular section/page etc
- The GTM tag will be normal pageview tag, you just need to put the virtual page path value in the More settings > Basic Configuration like shown below:
Solution 3:[3]
As pointed out in the article What Is Google Tag Manager? Do I Need It For My Website?, Google Tag Manager can listen to browser history changes, i.e. History Change is one of the pre-defined trigger in Tag Manager. So it's doable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ali Davut |
| Solution 2 | Tushar |
| Solution 3 | S. W. Wong |

