-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix sendGAEvent function params and type clearly #63226
base: canary
Are you sure you want to change the base?
Conversation
@@ -54,14 +54,14 @@ export function GoogleAnalytics(props: GAParams) { | |||
) | |||
} | |||
|
|||
export function sendGAEvent(..._args: Object[]) { | |||
export function sendGAEvent(eventName: string, eventParameters: {[key: string]: string | number}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this type is too restrictive.
Some gtag events take an items
parameter, which is an array of Item objects.
https://developers.google.com/tag-platform/gtagjs/reference/events
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review!
I can't find that items
parameters in recent docs about gtag.
https://developers.google.com/tag-platform/gtagjs/reference#event
If the items
parameter you're talking about is a gtag command, how about creating a function for each command separately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added type GA events include items
parameters you referenced.
If the event name entered by the user is the same as the event name in the link you referenced, it also provides autocomplete event parameters.
Can you check this changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your types won't allow custom events. Maybe there is an existing official set of types from Google that we could use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type allow custom events. And I also added types from Google docs.
And if user input types from Google official types, user can get autocomplete Google official params.
Also user can input custom types.
I pushed new commit. Please check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your maintaining. I know you're busy, but could you please check one more time, this commit would be very helpful.
Related: #65678 |
Sorry, I'm late. I checked that #66339. I think that PR is for type of GTM. I added types for GA. I added all google recommended events (reserved event params). Right now we can register any value, but I think merging these PRs will help people who aren't familiar with Google's suggested Params by autocomplete them. Can you enter this link one more? |
@hjick Thank you! If you can also look into the merge conflict, that will be great |
Sorry, I'm late. I will fix the conflict soon! |
I got some problem to fix this conflict errors.. I think there is not enough build error messages. |
The parameters of the sendGAEvent function type is too ambiguous, the function is working even if entered incorrectly.
I modified the parameters more clearly by referring to the document.
And I add example docs.
Why?
This is GA initialize code.
arguments is array-like object.
gtag('js', new Date())
is gonna bewindow['${dataLayerName}'].push({ 0: 'js', 1: newDate() })
So, the sendGAEvent function is weird.
Example sendGAEvent in docs now
sendGAEvent({ event: 'buttonClicked', value: 'xyz' })}
is gonna bewindow['${dataLayerName}'].push({ 0: { event: "buttonClicked", value: "xyz" })
But according to GA docs, it has to be
window['${dataLayerName}'].push({ 0: 'event', 1: '<event-name>', 2: { <event_parameters> } })
like GA4 event docs example
GA4 event docs:
https://developers.google.com/analytics/devguides/collection/ga4/events
issue reference:
#62065 (comment)