@mparticle/web-google-analytics-4-client-kit 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,7 +11,7 @@ npm i @mparticle/web-google-analytics-4-client-kit
11
11
 
12
12
  Full documentation on usage can be found [here](https://docs.mparticle.com/integrations/google-analytics-4/event/).
13
13
 
14
- #License
14
+ # License
15
15
 
16
16
  Copyright 2022 mParticle, Inc.
17
17
 
@@ -18,6 +18,10 @@ function truncateString(string, limit) {
18
18
  : string;
19
19
  }
20
20
 
21
+ function isEmpty(value) {
22
+ return value == null || !(Object.keys(value) || value).length;
23
+ }
24
+
21
25
  function Common() {}
22
26
 
23
27
  Common.prototype.forwarderSettings = null;
@@ -41,11 +45,13 @@ Common.prototype.truncateAttributes = function (
41
45
  ) {
42
46
  var truncatedAttributes = {};
43
47
 
44
- Object.keys(attributes).forEach(function (attribute) {
45
- var key = truncateString(attribute, keyLimit);
46
- var val = truncateString(attributes[attribute], valueLimit);
47
- truncatedAttributes[key] = val;
48
- });
48
+ if (!isEmpty(attributes)) {
49
+ Object.keys(attributes).forEach(function (attribute) {
50
+ var key = truncateString(attribute, keyLimit);
51
+ var val = truncateString(attributes[attribute], valueLimit);
52
+ truncatedAttributes[key] = val;
53
+ });
54
+ }
49
55
 
50
56
  return truncatedAttributes;
51
57
  };
@@ -749,6 +755,7 @@ var identityHandler = IdentityHandler;
749
755
 
750
756
  var initialization = {
751
757
  name: 'GoogleAnalytics4',
758
+ moduleId: 160,
752
759
  /* ****** Fill out initForwarder to load your SDK ******
753
760
  Note that not all arguments may apply to your SDK initialization.
754
761
  These are passed from mParticle, but leave them even if they are not being used.
@@ -767,6 +774,8 @@ var initialization = {
767
774
  isInitialized,
768
775
  common
769
776
  ) {
777
+ mParticle._setIntegrationDelay(this.moduleId, true);
778
+
770
779
  common.forwarderSettings = forwarderSettings;
771
780
  var measurementId = forwarderSettings.measurementId;
772
781
  var userIdType = forwarderSettings.externalUserIdentityType;
@@ -779,6 +788,25 @@ var initialization = {
779
788
  window.gtag = function () {
780
789
  window.dataLayer.push(arguments);
781
790
  };
791
+ gtag('js', new Date());
792
+
793
+ // Check to see if mParticle SDK is V2 because V1 does not have the
794
+ // Identity API
795
+ if (window.mParticle.getVersion().split('.')[0] === '2') {
796
+ var userId = common.getUserId(
797
+ mParticle.Identity.getCurrentUser(),
798
+ userIdType,
799
+ hashUserId
800
+ );
801
+ if (userId) {
802
+ configSettings.user_id = userId;
803
+ }
804
+ }
805
+ gtag('config', measurementId, configSettings);
806
+
807
+ gtag('get', measurementId, 'client_id', function (clientId) {
808
+ setClientId(clientId, initialization.moduleId);
809
+ });
782
810
 
783
811
  if (!testMode) {
784
812
  var clientScript = document.createElement('script');
@@ -792,19 +820,6 @@ var initialization = {
792
820
  ).appendChild(clientScript);
793
821
 
794
822
  clientScript.onload = function () {
795
- gtag('js', new Date());
796
-
797
- if (window.mParticle.getVersion().split('.')[0] === '2') {
798
- var userId = common.getUserId(
799
- mParticle.Identity.getCurrentUser(),
800
- userIdType,
801
- hashUserId
802
- );
803
- if (userId) {
804
- configSettings.user_id = userId;
805
- }
806
- }
807
- gtag('config', measurementId, configSettings);
808
823
  isInitialized = true;
809
824
 
810
825
  if (window.dataLayer && gtag && eventQueue.length > 0) {
@@ -821,6 +836,17 @@ var initialization = {
821
836
  },
822
837
  };
823
838
 
839
+ function setClientId(clientId, moduleId) {
840
+ var GA4CLIENTID = 'client_id';
841
+ var ga4IntegrationAttributes = {};
842
+ ga4IntegrationAttributes[GA4CLIENTID] = clientId;
843
+ window.mParticle.setIntegrationAttribute(
844
+ moduleId,
845
+ ga4IntegrationAttributes
846
+ );
847
+ window.mParticle._setIntegrationDelay(moduleId, false);
848
+ }
849
+
824
850
  var initialization_1 = initialization;
825
851
 
826
852
  var sessionHandler = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mparticle/web-google-analytics-4-client-kit",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
5
5
  "description": "mParticle integration sdk for Google Analytics",
6
6
  "main": "dist/GoogleAnalytics4EventForwarderClientSide-Kit.common.js",
@@ -25,22 +25,23 @@
25
25
  "@semantic-release/changelog": "^5.0.1",
26
26
  "@semantic-release/exec": "^5.0.0",
27
27
  "@semantic-release/git": "^9.0.0",
28
- "mocha": "^5.2.0",
29
28
  "chai": "^4.2.0",
29
+ "eslint": "^7.25.0",
30
+ "eslint-config-prettier": "8.3.0",
31
+ "eslint-plugin-prettier": "3.4.1",
30
32
  "karma": "^5.1.0",
31
33
  "karma-chai": "^0.1.0",
32
34
  "karma-chrome-launcher": "^3.1.0",
33
35
  "karma-firefox-launcher": "^1.3.0",
34
36
  "karma-mocha": "^2.0.1",
37
+ "mocha": "^5.2.0",
38
+ "prettier": "^2.4.1",
35
39
  "rollup": "^1.15.6",
36
40
  "rollup-plugin-commonjs": "^10.0.0",
37
41
  "rollup-plugin-node-resolve": "^5.0.3",
38
42
  "shelljs": "0.8.3",
39
- "eslint": "^7.25.0",
40
- "eslint-config-prettier": "8.3.0",
41
- "eslint-plugin-prettier": "3.4.1",
42
43
  "should": "13.2.3",
43
- "prettier": "^2.4.1",
44
+ "sinon": "^15.1.0",
44
45
  "watchify": "^3.11.0"
45
46
  },
46
47
  "dependencies": {