Skip to content

fix: Relocate config call earlier in kit initialization#34

Merged
rmi22186 merged 11 commits intodevelopmentfrom
fix/SQDSDKS-5101-refactor-config
Feb 17, 2023
Merged

fix: Relocate config call earlier in kit initialization#34
rmi22186 merged 11 commits intodevelopmentfrom
fix/SQDSDKS-5101-refactor-config

Conversation

@rmi22186
Copy link
Copy Markdown
Collaborator

Summary

Part of setting up GA4 is having a dataLayer set up, which requires a config call as well. The docs show that this should be set up immediately after the dataLayer is initialized, along with a js call.

Previously, in the GA4 kit, the initial call to config happened inside of a .onload function 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 the dataLayer the 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 .onload function where it belongs, directly below the dataLayer being 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 config and js calls in it, I reset the dataLayer to [] since a lot of places check for dataLayer[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

Comment thread packages/GA4Client/test/src/tests.js Outdated
Comment thread packages/GA4Client/test/src/tests.js Outdated
Comment thread packages/GA4Client/src/initialization.js
Comment thread packages/GA4Client/test/src/tests.js Outdated
Comment thread packages/GA4Client/src/common.js Outdated
Comment thread packages/GA4Client/test/src/tests.js Outdated
Comment thread packages/GA4Client/test/src/tests.js Outdated
Comment thread packages/GA4Client/test/src/tests.js Outdated
rmi22186 and others added 10 commits February 17, 2023 15:33
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>
Co-authored-by: Alex S <49695018+alexs-mparticle@users.noreply.github.com>
@rmi22186 rmi22186 force-pushed the fix/SQDSDKS-5101-refactor-config branch from 477e68a to 7bf61c8 Compare February 17, 2023 20:34
Comment thread packages/GA4Client/test/src/tests.js
@rmi22186 rmi22186 merged commit 4587fda into development Feb 17, 2023
@rmi22186 rmi22186 deleted the fix/SQDSDKS-5101-refactor-config branch February 17, 2023 20:49
github-actions Bot pushed a commit that referenced this pull request Feb 22, 2023
## [1.0.6](v1.0.5...v1.0.6) (2023-02-22)

### Bug Fixes

* Check if Event Attributes are empty before truncating ([#35](#35)) ([c17f92b](c17f92b))
* Relocate config call earlier in kit initialization ([#34](#34)) ([4587fda](4587fda))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants