Add Client ID snippet to Gtag code example #5041
Merged
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.
Proposed changes
On sending events from both browser and server, GA4 Web docs mention:
With Google Analytics 4 Web, events are sent from the browser to GA4. If you use Segment’s Google Analytics 4 Cloud destination to send events through the API and tie data between client-side and server-side, you need to pass the same Client ID from the browser and the server. To do this, fetch the Gtag-generated clientId on the web client and pass it to Segment as a property. For more information, see Google Analytics 4 destination: User Identification on the next steps.
However, the GA4 Cloud Mode docs' section on using Gtag.js and GA4 Cloud mode do not show an example of retrieving the Client ID with Gtag, nor does it directly state that the user identification between the two implementations should be the same.
Modified the code example to demonstrate this, along with directly stating:
Additionally, client_id must also align between client-side and server-side events in order to deduplicate user counts in GA4 (unless User-ID is used as the basis for user identification).
Merge timing
Related issues (optional)