sendGTMEvent in @next/third-parties should push the event into the dataLayer even before the GTM script itself is loaded in and initialized #66865
SanderRuusmaa
started this conversation in
Ideas
Replies: 1 comment
-
Here's my stab at the issue #68683 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
Non-Goals
No response
Background
Expanding on goal the purpose of the goal:
The initial dataLayer pushes are basically lost if the GTM script itself is not initialized when they should be buffered to be sent to GTM.
For example pushing the initial page_view event to the dataLayer does not work via sendGTMEvent because the currDataLayerName is undefined due the GTM script itself not being initialized. The result is that this event push is lost, because the source code of sendGTMEvent exits the function with an empty return when currDataLayerName === undefined.
The events that are sent after GTM's script is initialized are received properly in GTM.
This is a problem we faced in a production app. The workaround for it was to create a custom function event sending function:
Of course it lacks the custom data layer name functionality, but that can be also taken into account when actually tweaking the GoogleTagManager component.
Proposal
The window[currDataLayerName] should be initialized (as an empty list) when the first sendGTMEvent functions gets called before GTM is initialized.
The first events that get pushed to the dataLayer should still be sent to GTM after GTM's code gets initialized. Currently the first events sent prior the GTM's initialization are lost.
Beta Was this translation helpful? Give feedback.
All reactions