feat: add type-safe overloads for sendGAEvent with GA4 recommended event types#91910
Open
hjick wants to merge 1 commit intovercel:canaryfrom
Open
feat: add type-safe overloads for sendGAEvent with GA4 recommended event types#91910hjick wants to merge 1 commit intovercel:canaryfrom
hjick wants to merge 1 commit intovercel:canaryfrom
Conversation
…ent types The sendGAEvent function parameter type was too ambiguous (Object[]), providing no autocomplete for GA4 recommended events. - Add TypeScript overloads for full backward compatibility - Add 37 GA4 recommended event type definitions based on official docs - No runtime behavior changes (window[dataLayer].push(arguments) preserved)
Contributor
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
| ): void | ||
| // Legacy overload: backward compatible with any arguments | ||
| export function sendGAEvent(..._args: Object[]): void | ||
|
|
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Add TypeScript overload signatures to the
sendGAEventfunction in@next/third-parties/googleand define GA4 recommended event types for autocomplete support.Why?
The current
sendGAEventfunction accepts...args: Object[], which is too ambiguous — it provides no autocomplete or type checking for GA4 event parameters. This makes it easy to pass incorrect arguments without any IDE feedback.Related: #63226, #62065
According to the GA4 gtag.js event reference, events should follow the pattern:
How?
TypeScript overloads (no runtime changes):
purchase,add_to_cart,login, etc.) with their exact parameter typessendGAEvent('event', 'my_event', { key: 'value' })sendGAEvent(...args: Object[])preserved for full backward compatibilityThe runtime implementation remains unchanged (
window[dataLayer].push(arguments)), so existing code continues to work without modification.GA4 recommended event types include:
add_payment_info,add_shipping_info,add_to_cart,add_to_wishlist,begin_checkout,purchase,refund,remove_from_cart,select_item,select_promotion,view_cart,view_item,view_item_list,view_promotionclose_convert_lead,close_unconvert_lead,disqualify_lead,generate_lead,qualify_lead,working_leadlevel_end,level_start,level_up,post_score,unlock_achievementearn_virtual_currency,exception,join_group,login,page_view,search,select_content,share,sign_up,spend_virtual_currency,tutorial_begin,tutorial_complete,view_search_resultsUsage example:
For Contributors
Adding a feature
fixes #number