fix: Relocate config call earlier in kit initialization#34
Merged
rmi22186 merged 11 commits intodevelopmentfrom Feb 17, 2023
Merged
fix: Relocate config call earlier in kit initialization#34rmi22186 merged 11 commits intodevelopmentfrom
rmi22186 merged 11 commits intodevelopmentfrom
Conversation
alexs-mparticle
requested changes
Feb 17, 2023
alexs-mparticle
requested changes
Feb 17, 2023
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
This reverts commit b54d17e.
This reverts commit 2de645e.
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
477e68a to
7bf61c8
Compare
alexs-mparticle
approved these changes
Feb 17, 2023
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.
Summary
Part of setting up GA4 is having a
dataLayerset up, which requires aconfigcall as well. The docs show that this should be set up immediately after thedataLayeris initialized, along with ajscall.Previously, in the GA4 kit, the initial call to config happened inside of a
.onloadfunction because we wanted to increase the likelihood of there being a user first (note the user logic immediately preceding the function). However, the issue with this is there is a chance a user sends an event with attributes before this config is called. If this happens, in thedataLayerthe page event exists prior to the config, and the config which has no attributes will prevent the page event from including attributes at all (a quirk of Google's SDK). To avoid this, we move the config call out of the.onloadfunction where it belongs, directly below thedataLayerbeing initialized.This ends up not posing an issue with getting the user on it, because the user also gets added on onUserIdentified.
Testing Plan
Fixed unit tests. Since the dataLayer is going to have the
configandjscalls in it, I reset thedataLayerto[]since a lot of places check fordataLayer[0]which without resetting it, would return the config or js item in the dataLayer.Tested locally.
Master Issue
Closes https://go.mparticle.com/work/SQDSDKS-5101