I am trying to implement conversions API on our page and of course the main issue is the deduplication of events. The way I avoid this, is using same event names and same event IDs (random unique variable generated at specific time). As I understand it, Google Tag Manager (GTM) will fire tags when certain conditions are met (for example page load), and send the events to the pixel. I am trying to send the same event from our page's javascript. For the simplicity's sake, I started with the 'pageView' event.
I am trying to achieve all of this with only Tag Manager and our code (not using Google's Tag Manager Server-side option)
I've implemented some methods to try get the dataLayer variable (I defined a new one, called EventID), but I see that the value is stored in the dataLayer when the page loads - however, when checking my events, it shows that event id is undefined (the value of the dataLayer's EventID variable was not yet set at the time when my function was called. So events are sent with 'undefined' eventID's, but when I open dev console and check the dataLayer variable the expected random eventID number is there.
I've also added a new tag called "datalayer Event ID" which is supposed to fire when page loads and store the newly generated event id to dataLayer where it can get fetched. The code is simple and it looks like this:
<script>
ID = [our FB Pixel ID] + Date.now();
dataLayer.push({'eventID' : ID});
</script>
Could someone with more experience please comment on this:
- Is this way of doing it correct? Am I missing some triggers/should define different time/place when this tag should fire?
- Is there a different approach I should take to implement the deduplication?
Thanks for any info!
Just pushing eventID to dataLayer will change nothing in your case. You need to change the configuration of the FB tag itself.
Not sure why you don't want to use sGTM because looks like this is the easiest option for you.
Here is a good blog post on how to set up Facebook event deduplication in Google Tag Manager