Replies: 1 comment 2 replies
-
A small addendum: presumably since |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Goals
Non-Goals
Background
The
sendGTMEvent
function currently takes anObject
parameter, which could be basically any object in the world. Usually there is some kind of consistent structure of an object to send to Google, but it depends on how GTM is implement at the customer's side.For that reason, it is helpful if we the developers could supply what that structure is, that the implemented GTM expects to recieve.
Proposal
1. A hook function
The
GoogleTagManager
provider recieves a generic parameter that dictates the type of data that can be supplied into the send function throughout the app.That template is there to infer the type, since React component cannot be explicitly generic. Several libraries exist that do it that way, and it works really well. Essentially, the
GoogleTagManager
props need to be extended with one extra prop:It would then provide a context with automagically the same generic, and a hook function to recieve the send function. I haven't thought that out in detail, but I'm sure it can work. Hopefully 🙏🏻
2. Generic send function
This one is compatible with the current set up.
Add a generic parameter to the
sendGTMEvent
function and be done with it:The only disadvantage is that we, as developers, need to never forget to supply it that generic parameter with each and every call, in order to maintain type safety. Otherwise it'll fall back to
Object
.Beta Was this translation helpful? Give feedback.
All reactions