@mparticle/web-google-analytics-4-server-kit 1.0.1 → 1.0.3
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
|
@@ -22,11 +22,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
22
22
|
// This kit does not have a `processEvent` method because no events should be sent client side.
|
|
23
23
|
|
|
24
24
|
var name = 'GoogleAnalytics4',
|
|
25
|
-
GA4MODULENUMBER = 160
|
|
25
|
+
GA4MODULENUMBER = 160,
|
|
26
|
+
suffix = 'Server';
|
|
26
27
|
|
|
27
28
|
var constructor = function() {
|
|
28
29
|
var self = this;
|
|
29
30
|
self.name = name;
|
|
31
|
+
self.suffix = suffix;
|
|
30
32
|
|
|
31
33
|
function initForwarder(forwarderSettings, service, testMode) {
|
|
32
34
|
mParticle._setIntegrationDelay(GA4MODULENUMBER, true);
|
|
@@ -38,6 +40,12 @@ var constructor = function() {
|
|
|
38
40
|
window.dataLayer.push(arguments);
|
|
39
41
|
};
|
|
40
42
|
|
|
43
|
+
gtag('js', new Date());
|
|
44
|
+
|
|
45
|
+
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
46
|
+
setClientId(clientId, GA4MODULENUMBER);
|
|
47
|
+
});
|
|
48
|
+
|
|
41
49
|
if (!testMode) {
|
|
42
50
|
var clientScript = document.createElement('script');
|
|
43
51
|
clientScript.type = 'text/javascript';
|
|
@@ -48,21 +56,12 @@ var constructor = function() {
|
|
|
48
56
|
document.getElementsByTagName('head')[0] ||
|
|
49
57
|
document.getElementsByTagName('body')[0]
|
|
50
58
|
).appendChild(clientScript);
|
|
51
|
-
|
|
52
|
-
clientScript.onload = function() {
|
|
53
|
-
gtag('js', new Date());
|
|
54
|
-
|
|
55
|
-
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
56
|
-
setClientId(clientId, GA4MODULENUMBER);
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
};
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
this.init = initForwarder;
|
|
64
63
|
};
|
|
65
|
-
|
|
64
|
+
|
|
66
65
|
function setClientId(clientId, GA4MODULENUMBER) {
|
|
67
66
|
var GA4CLIENTID = 'client_id';
|
|
68
67
|
var ga4IntegrationAttributes = {};
|
|
@@ -83,13 +82,18 @@ if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
|
83
82
|
name: name,
|
|
84
83
|
constructor: constructor,
|
|
85
84
|
getId: getId,
|
|
85
|
+
// A suffix is added if there are multiple different versions of
|
|
86
|
+
// a client kit. This matches the suffix in the DB.
|
|
87
|
+
suffix: suffix,
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
function register(config) {
|
|
92
|
+
var forwarderNameWithSuffix = [name, suffix].join('-');
|
|
90
93
|
if (!config) {
|
|
91
94
|
window.console.log(
|
|
92
|
-
'You must pass a config object to register the kit ' +
|
|
95
|
+
'You must pass a config object to register the kit ' +
|
|
96
|
+
forwarderNameWithSuffix
|
|
93
97
|
);
|
|
94
98
|
return;
|
|
95
99
|
}
|
|
@@ -102,17 +106,19 @@ function register(config) {
|
|
|
102
106
|
}
|
|
103
107
|
|
|
104
108
|
if (isObject(config.kits)) {
|
|
105
|
-
config.kits[
|
|
109
|
+
config.kits[forwarderNameWithSuffix] = {
|
|
106
110
|
constructor: constructor,
|
|
107
111
|
};
|
|
108
112
|
} else {
|
|
109
113
|
config.kits = {};
|
|
110
|
-
config.kits[
|
|
114
|
+
config.kits[forwarderNameWithSuffix] = {
|
|
111
115
|
constructor: constructor,
|
|
112
116
|
};
|
|
113
117
|
}
|
|
114
118
|
window.console.log(
|
|
115
|
-
'Successfully registered ' +
|
|
119
|
+
'Successfully registered ' +
|
|
120
|
+
forwarderNameWithSuffix +
|
|
121
|
+
' to your mParticle configuration'
|
|
116
122
|
);
|
|
117
123
|
}
|
|
118
124
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-google-analytics-4-server-kit",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "mParticle integration sdk for Google Analytics (server side)",
|
|
5
5
|
"main": "dist/GoogleAnalytics4EventForwarderServerSide-Kit.common.js",
|
|
6
|
-
"browser": "dist/GoogleAnalytics4EventForwarderServerSide-Kit.
|
|
6
|
+
"browser": "dist/GoogleAnalytics4EventForwarderServerSide-Kit.common.js",
|
|
7
|
+
"files": ["dist/GoogleAnalytics4EventForwarderServerSide-Kit.common.js"],
|
|
7
8
|
"scripts": {
|
|
8
9
|
"build": "rollup --config rollup.config.js",
|
|
9
|
-
"
|
|
10
|
+
"build:test": "ENVIRONMENT=production rollup --config rollup.test.config.js",
|
|
11
|
+
"watch": "rollup --config rollup.config.js -w",
|
|
12
|
+
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js",
|
|
13
|
+
"test:debug": "npm run build && npm run build:test && DEBUG=true karma start test/karma.config.js"
|
|
14
|
+
|
|
10
15
|
},
|
|
11
16
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
12
17
|
"license": "Apache-2.0",
|
|
@@ -15,6 +20,14 @@
|
|
|
15
20
|
},
|
|
16
21
|
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-google-analytics-4/tree/master/packages/GA4Server",
|
|
17
22
|
"devDependencies": {
|
|
18
|
-
"
|
|
23
|
+
"mocha": "^5.2.0",
|
|
24
|
+
"rollup": "^1.15.6",
|
|
25
|
+
"rollup-plugin-commonjs": "^10.0.0",
|
|
26
|
+
"rollup-plugin-node-resolve": "^5.0.3",
|
|
27
|
+
"should": "13.2.3",
|
|
28
|
+
"sinon": "^15.1.0"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@mparticle/web-sdk": "^2.23.0"
|
|
19
32
|
}
|
|
20
33
|
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
var mParticleGA4 = (function (exports) {
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
// Copyright 2022 mParticle, Inc.
|
|
6
|
-
//
|
|
7
|
-
// Licensed under the Apache License, Version 2.0 (the 'License');
|
|
8
|
-
// you may not use this file except in compliance with the License.
|
|
9
|
-
// You may obtain a copy of the License at
|
|
10
|
-
//
|
|
11
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
-
//
|
|
13
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
14
|
-
// distributed under the License is distributed on an 'AS IS' BASIS,
|
|
15
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
-
// See the License for the specific language governing permissions and
|
|
17
|
-
// limitations under the License.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// This GA4 server side kit loads gtag, gets the client id, and sets it as an integration attribute on the core sdk.
|
|
21
|
-
// This kit does not have a `processEvent` method because no events should be sent client side.
|
|
22
|
-
|
|
23
|
-
var name = 'GoogleAnalytics4',
|
|
24
|
-
GA4MODULENUMBER = 160;
|
|
25
|
-
|
|
26
|
-
var constructor = function() {
|
|
27
|
-
var self = this;
|
|
28
|
-
self.name = name;
|
|
29
|
-
|
|
30
|
-
function initForwarder(forwarderSettings, service, testMode) {
|
|
31
|
-
mParticle._setIntegrationDelay(GA4MODULENUMBER, true);
|
|
32
|
-
|
|
33
|
-
var measurementId = forwarderSettings.measurementId;
|
|
34
|
-
window.dataLayer = window.dataLayer || [];
|
|
35
|
-
|
|
36
|
-
window.gtag = function() {
|
|
37
|
-
window.dataLayer.push(arguments);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (!testMode) {
|
|
41
|
-
var clientScript = document.createElement('script');
|
|
42
|
-
clientScript.type = 'text/javascript';
|
|
43
|
-
clientScript.async = true;
|
|
44
|
-
clientScript.src =
|
|
45
|
-
'https://www.googletagmanager.com/gtag/js?id=' + measurementId;
|
|
46
|
-
(
|
|
47
|
-
document.getElementsByTagName('head')[0] ||
|
|
48
|
-
document.getElementsByTagName('body')[0]
|
|
49
|
-
).appendChild(clientScript);
|
|
50
|
-
|
|
51
|
-
clientScript.onload = function() {
|
|
52
|
-
gtag('js', new Date());
|
|
53
|
-
|
|
54
|
-
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
55
|
-
setClientId(clientId, GA4MODULENUMBER);
|
|
56
|
-
});
|
|
57
|
-
return;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this.init = initForwarder;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
function setClientId(clientId, GA4MODULENUMBER) {
|
|
66
|
-
var GA4CLIENTID = 'client_id';
|
|
67
|
-
var ga4IntegrationAttributes = {};
|
|
68
|
-
ga4IntegrationAttributes[GA4CLIENTID] = clientId;
|
|
69
|
-
mParticle.setIntegrationAttribute(
|
|
70
|
-
GA4MODULENUMBER,
|
|
71
|
-
ga4IntegrationAttributes
|
|
72
|
-
);
|
|
73
|
-
mParticle._setIntegrationDelay(GA4MODULENUMBER, false);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function getId() {
|
|
77
|
-
return GA4MODULENUMBER;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
81
|
-
window.mParticle.addForwarder({
|
|
82
|
-
name: name,
|
|
83
|
-
constructor: constructor,
|
|
84
|
-
getId: getId,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function register(config) {
|
|
89
|
-
if (!config) {
|
|
90
|
-
window.console.log(
|
|
91
|
-
'You must pass a config object to register the kit ' + name
|
|
92
|
-
);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!isObject(config)) {
|
|
97
|
-
window.console.log(
|
|
98
|
-
"'config' must be an object. You passed in a " + typeof config
|
|
99
|
-
);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (isObject(config.kits)) {
|
|
104
|
-
config.kits[name] = {
|
|
105
|
-
constructor: constructor,
|
|
106
|
-
};
|
|
107
|
-
} else {
|
|
108
|
-
config.kits = {};
|
|
109
|
-
config.kits[name] = {
|
|
110
|
-
constructor: constructor,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
window.console.log(
|
|
114
|
-
'Successfully registered ' + name + ' to your mParticle configuration'
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function isObject(val) {
|
|
119
|
-
return (
|
|
120
|
-
val != null && typeof val === 'object' && Array.isArray(val) === false
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var GoogleAnalytics4EventForwarderServerSide = {
|
|
125
|
-
register: register,
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
exports.default = GoogleAnalytics4EventForwarderServerSide;
|
|
129
|
-
|
|
130
|
-
return exports;
|
|
131
|
-
|
|
132
|
-
}({}));
|
package/rollup.config.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const input = 'src/GoogleAnalytics4EventForwarderServerSide.js';
|
|
2
|
-
|
|
3
|
-
const outputOptions = {
|
|
4
|
-
exports: 'named',
|
|
5
|
-
strict: false,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const builds = {
|
|
9
|
-
// for dynamic script tag loading of GA4 server side kit
|
|
10
|
-
server_iife: {
|
|
11
|
-
input,
|
|
12
|
-
output: {
|
|
13
|
-
...outputOptions,
|
|
14
|
-
name: 'mParticleGA4',
|
|
15
|
-
file: 'dist/GoogleAnalytics4EventForwarderServerSide-Kit.iife.js',
|
|
16
|
-
format: 'iife',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
// creates npm module for GA4 server side kit
|
|
20
|
-
server_cjs: {
|
|
21
|
-
input,
|
|
22
|
-
output: {
|
|
23
|
-
...outputOptions,
|
|
24
|
-
name: 'mParticleGA4',
|
|
25
|
-
file: 'dist/GoogleAnalytics4EventForwarderServerSide-Kit.common.js',
|
|
26
|
-
format: 'cjs',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default [builds.server_iife, builds.server_cjs];
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
// Copyright 2022 mParticle, Inc.
|
|
5
|
-
//
|
|
6
|
-
// Licensed under the Apache License, Version 2.0 (the 'License');
|
|
7
|
-
// you may not use this file except in compliance with the License.
|
|
8
|
-
// You may obtain a copy of the License at
|
|
9
|
-
//
|
|
10
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
//
|
|
12
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
// distributed under the License is distributed on an 'AS IS' BASIS,
|
|
14
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
// See the License for the specific language governing permissions and
|
|
16
|
-
// limitations under the License.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// This GA4 server side kit loads gtag, gets the client id, and sets it as an integration attribute on the core sdk.
|
|
20
|
-
// This kit does not have a `processEvent` method because no events should be sent client side.
|
|
21
|
-
|
|
22
|
-
var name = 'GoogleAnalytics4',
|
|
23
|
-
GA4MODULENUMBER = 160;
|
|
24
|
-
|
|
25
|
-
var constructor = function() {
|
|
26
|
-
var self = this;
|
|
27
|
-
self.name = name;
|
|
28
|
-
|
|
29
|
-
function initForwarder(forwarderSettings, service, testMode) {
|
|
30
|
-
mParticle._setIntegrationDelay(GA4MODULENUMBER, true);
|
|
31
|
-
|
|
32
|
-
var measurementId = forwarderSettings.measurementId;
|
|
33
|
-
window.dataLayer = window.dataLayer || [];
|
|
34
|
-
|
|
35
|
-
window.gtag = function() {
|
|
36
|
-
window.dataLayer.push(arguments);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
if (!testMode) {
|
|
40
|
-
var clientScript = document.createElement('script');
|
|
41
|
-
clientScript.type = 'text/javascript';
|
|
42
|
-
clientScript.async = true;
|
|
43
|
-
clientScript.src =
|
|
44
|
-
'https://www.googletagmanager.com/gtag/js?id=' + measurementId;
|
|
45
|
-
(
|
|
46
|
-
document.getElementsByTagName('head')[0] ||
|
|
47
|
-
document.getElementsByTagName('body')[0]
|
|
48
|
-
).appendChild(clientScript);
|
|
49
|
-
|
|
50
|
-
clientScript.onload = function() {
|
|
51
|
-
gtag('js', new Date());
|
|
52
|
-
|
|
53
|
-
gtag('get', measurementId, 'client_id', function(clientId) {
|
|
54
|
-
setClientId(clientId, GA4MODULENUMBER);
|
|
55
|
-
});
|
|
56
|
-
return;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.init = initForwarder;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function setClientId(clientId, GA4MODULENUMBER) {
|
|
65
|
-
var GA4CLIENTID = 'client_id';
|
|
66
|
-
var ga4IntegrationAttributes = {};
|
|
67
|
-
ga4IntegrationAttributes[GA4CLIENTID] = clientId;
|
|
68
|
-
mParticle.setIntegrationAttribute(
|
|
69
|
-
GA4MODULENUMBER,
|
|
70
|
-
ga4IntegrationAttributes
|
|
71
|
-
);
|
|
72
|
-
mParticle._setIntegrationDelay(GA4MODULENUMBER, false);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function getId() {
|
|
76
|
-
return GA4MODULENUMBER;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
80
|
-
window.mParticle.addForwarder({
|
|
81
|
-
name: name,
|
|
82
|
-
constructor: constructor,
|
|
83
|
-
getId: getId,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function register(config) {
|
|
88
|
-
if (!config) {
|
|
89
|
-
window.console.log(
|
|
90
|
-
'You must pass a config object to register the kit ' + name
|
|
91
|
-
);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (!isObject(config)) {
|
|
96
|
-
window.console.log(
|
|
97
|
-
"'config' must be an object. You passed in a " + typeof config
|
|
98
|
-
);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (isObject(config.kits)) {
|
|
103
|
-
config.kits[name] = {
|
|
104
|
-
constructor: constructor,
|
|
105
|
-
};
|
|
106
|
-
} else {
|
|
107
|
-
config.kits = {};
|
|
108
|
-
config.kits[name] = {
|
|
109
|
-
constructor: constructor,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
window.console.log(
|
|
113
|
-
'Successfully registered ' + name + ' to your mParticle configuration'
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function isObject(val) {
|
|
118
|
-
return (
|
|
119
|
-
val != null && typeof val === 'object' && Array.isArray(val) === false
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default {
|
|
124
|
-
register: register,
|
|
125
|
-
};
|