Repository navigation
docs: add recipes for Google click IDs and form field services - #232
Merged
Merged
Conversation
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.
Two ideas were proposed for the module: Google Analytics integration and output formats other than JSON. Both are better served by documentation than by new features. GA4 already reads the same UTM and Google click parameters from the landing URL and attributes sessions itself. The attribution snapshot is plain data, so its format belongs to whatever receives it. This adds
docs/RECIPES.md, linked from the README header and from the form example.getGoogleAnalyticsClientId()asksgtagfor the client ID with a timeout, so the lead is still sent when gtag.js is blocked or consent mode holds it back. The backend can then report later lead events through the Measurement Protocol. The recipe notes that Google's policy forbids sending personally identifiable information, including in URLs.latestGoogleAdsClick()searches the whole history for the most recent entry withgclid,gbraid, orwbraid, since the last touch may be a later campaign without a Google click. Google says to store the GCLID with the lead for offline conversion import, and to send bothgclidandgbraidwhen a conversion has both.attributionFields()flattens first and last touch into fixed field names such asfirst_utm_sourceand returnsURLSearchParams, which$fetchsends asapplication/x-www-form-urlencoded.The package consumer fixture includes copies of the two helpers that use the module's types, so
pnpm test:packagefails if the published types stop supporting them. I also type-checked the GA helper and its form handler separately understrictwith the DOM library.Validation:
pnpm format:check,pnpm lint --max-warnings 0, andpnpm test:packagepass.