@technoapple/ga4 1.0.3 → 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/.github/workflows/node.js.yml +31 -31
- package/.prettierignore +1 -1
- package/LICENSE +21 -21
- package/README.md +386 -48
- package/REQUIREMENTS.md +548 -0
- package/babel.config.js +5 -5
- package/build/main/dataLayer.d.ts +1 -1
- package/build/main/dataLayer.js +60 -10
- package/build/main/ga4/ga4.d.ts +13 -0
- package/build/main/ga4/ga4.js +24 -1
- package/build/main/helpers/debounce.d.ts +5 -0
- package/build/main/helpers/debounce.js +23 -0
- package/build/main/helpers/delegate.d.ts +8 -0
- package/build/main/helpers/delegate.js +37 -0
- package/build/main/helpers/dom-ready.d.ts +1 -0
- package/build/main/helpers/dom-ready.js +13 -0
- package/build/main/helpers/parse-url.d.ts +11 -0
- package/build/main/helpers/parse-url.js +32 -0
- package/build/main/helpers/session.d.ts +4 -0
- package/build/main/helpers/session.js +50 -0
- package/build/main/index.d.ts +9 -0
- package/build/main/index.js +19 -2
- package/build/main/plugins/clean-url-tracker.d.ts +17 -0
- package/build/main/plugins/clean-url-tracker.js +105 -0
- package/build/main/plugins/event-tracker.d.ts +27 -0
- package/build/main/plugins/event-tracker.js +76 -0
- package/build/main/plugins/impression-tracker.d.ts +32 -0
- package/build/main/plugins/impression-tracker.js +202 -0
- package/build/main/plugins/index.d.ts +8 -0
- package/build/main/plugins/index.js +20 -0
- package/build/main/plugins/media-query-tracker.d.ts +20 -0
- package/build/main/plugins/media-query-tracker.js +96 -0
- package/build/main/plugins/outbound-form-tracker.d.ts +17 -0
- package/build/main/plugins/outbound-form-tracker.js +55 -0
- package/build/main/plugins/outbound-link-tracker.d.ts +19 -0
- package/build/main/plugins/outbound-link-tracker.js +63 -0
- package/build/main/plugins/page-visibility-tracker.d.ts +24 -0
- package/build/main/plugins/page-visibility-tracker.js +93 -0
- package/build/main/plugins/url-change-tracker.d.ts +20 -0
- package/build/main/plugins/url-change-tracker.js +76 -0
- package/build/main/types/plugins.d.ts +78 -0
- package/build/main/types/plugins.js +3 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/docs/examples/react.md +95 -0
- package/docs/examples/vanilla.md +65 -0
- package/docs/examples/vue.md +87 -0
- package/jest.config.ts +195 -195
- package/package.json +56 -52
- package/src/dataLayer.ts +85 -23
- package/src/ga4/ga4.ts +69 -40
- package/src/ga4/ga4option.ts +4 -4
- package/src/ga4/index.ts +4 -4
- package/src/helpers/debounce.ts +28 -0
- package/src/helpers/delegate.ts +51 -0
- package/src/helpers/dom-ready.ts +7 -0
- package/src/helpers/parse-url.ts +37 -0
- package/src/helpers/session.ts +39 -0
- package/src/index.ts +34 -7
- package/src/plugins/clean-url-tracker.ts +112 -0
- package/src/plugins/event-tracker.ts +90 -0
- package/src/plugins/impression-tracker.ts +230 -0
- package/src/plugins/index.ts +8 -0
- package/src/plugins/media-query-tracker.ts +116 -0
- package/src/plugins/outbound-form-tracker.ts +65 -0
- package/src/plugins/outbound-link-tracker.ts +72 -0
- package/src/plugins/page-visibility-tracker.ts +104 -0
- package/src/plugins/url-change-tracker.ts +84 -0
- package/src/types/dataLayer.ts +9 -9
- package/src/types/global.ts +12 -12
- package/src/types/gtag.ts +259 -259
- package/src/types/plugins.ts +98 -0
- package/src/util.ts +18 -18
- package/test/dataLayer.spec.ts +55 -40
- package/test/ga4.spec.ts +36 -36
- package/tsconfig.json +28 -28
- package/tsconfig.module.json +11 -11
package/src/util.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
function findLast<T>(
|
|
2
|
-
list: Array<T>
|
|
3
|
-
, predicate: (value: T, index: number, obj: T[]) => unknown)
|
|
4
|
-
: T | undefined {
|
|
5
|
-
|
|
6
|
-
for (let index = list.length - 1; index >= 0; index--) {
|
|
7
|
-
let currentValue = list[index];
|
|
8
|
-
let predicateResult = predicate(currentValue, index, list);
|
|
9
|
-
if (predicateResult) {
|
|
10
|
-
return currentValue;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export {findLast};
|
|
18
|
-
|
|
1
|
+
function findLast<T>(
|
|
2
|
+
list: Array<T>
|
|
3
|
+
, predicate: (value: T, index: number, obj: T[]) => unknown)
|
|
4
|
+
: T | undefined {
|
|
5
|
+
|
|
6
|
+
for (let index = list.length - 1; index >= 0; index--) {
|
|
7
|
+
let currentValue = list[index];
|
|
8
|
+
let predicateResult = predicate(currentValue, index, list);
|
|
9
|
+
if (predicateResult) {
|
|
10
|
+
return currentValue;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {findLast};
|
|
18
|
+
|
package/test/dataLayer.spec.ts
CHANGED
|
@@ -1,41 +1,56 @@
|
|
|
1
|
-
import {} from '../src/types/global';
|
|
2
|
-
import {dataLayerHelper} from '../src/index';
|
|
3
|
-
import {findLast} from '../src/util';
|
|
4
|
-
|
|
5
|
-
describe('test dataLayer get function', () => {
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
window.dataLayer = [];
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('by default dataLayer get should return the 1st item', () => {
|
|
11
|
-
|
|
12
|
-
window.dataLayer = window.dataLayer || [];
|
|
13
|
-
|
|
14
|
-
window.dataLayer.push({
|
|
15
|
-
'test': 1
|
|
16
|
-
});
|
|
17
|
-
window.dataLayer.push({
|
|
18
|
-
'test': 11
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const result = dataLayerHelper.get('test');
|
|
22
|
-
expect(result).toBe(1);
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
test('
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
'
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import {} from '../src/types/global';
|
|
2
|
+
import {dataLayerHelper} from '../src/index';
|
|
3
|
+
import {findLast} from '../src/util';
|
|
4
|
+
|
|
5
|
+
describe('test dataLayer get function', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
window.dataLayer = [];
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('by default dataLayer get should return the 1st item', () => {
|
|
11
|
+
|
|
12
|
+
window.dataLayer = window.dataLayer || [];
|
|
13
|
+
|
|
14
|
+
window.dataLayer.push({
|
|
15
|
+
'test': 1
|
|
16
|
+
});
|
|
17
|
+
window.dataLayer.push({
|
|
18
|
+
'test': 11
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const result = dataLayerHelper.get('test');
|
|
22
|
+
expect(result).toBe(1);
|
|
23
|
+
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('If dataLayer array has object use the key should get the value', () => {
|
|
27
|
+
|
|
28
|
+
const data = [
|
|
29
|
+
{event: 'test'},
|
|
30
|
+
['js'],
|
|
31
|
+
['config', 'g-123'],
|
|
32
|
+
['event', 'conversion', {'allow': true}]
|
|
33
|
+
];
|
|
34
|
+
window.dataLayer = data;
|
|
35
|
+
|
|
36
|
+
const result = dataLayerHelper.get('allow');
|
|
37
|
+
expect(result).toBe(true);
|
|
38
|
+
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('if get last is true should return the last item', () => {
|
|
42
|
+
|
|
43
|
+
window.dataLayer = window.dataLayer || [];
|
|
44
|
+
|
|
45
|
+
window.dataLayer.push({
|
|
46
|
+
'test': 1
|
|
47
|
+
});
|
|
48
|
+
window.dataLayer.push({
|
|
49
|
+
'test': 11
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const result = dataLayerHelper.get('test', true);
|
|
53
|
+
expect(result).toBe(11);
|
|
54
|
+
|
|
55
|
+
});
|
|
41
56
|
});
|
package/test/ga4.spec.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
import {} from '../src/types/global';
|
|
2
|
-
import { ga4 } from '../src/index';
|
|
3
|
-
import { ga4Option } from '../src/ga4/ga4option';
|
|
4
|
-
|
|
5
|
-
describe('test ga4', () => {
|
|
6
|
-
test('init ga4 should call gtag', () => {
|
|
7
|
-
|
|
8
|
-
window.gtag = jest.fn();
|
|
9
|
-
|
|
10
|
-
ga4.init({
|
|
11
|
-
targetId: 'g-123'
|
|
12
|
-
} as ga4Option);
|
|
13
|
-
|
|
14
|
-
ga4.send('test', {
|
|
15
|
-
'test': 1
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
expect(window.gtag).toBeCalledTimes(3);
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
test('init ga4 able to use gtag at ga4', () => {
|
|
23
|
-
|
|
24
|
-
window.gtag = jest.fn();
|
|
25
|
-
|
|
26
|
-
ga4.init({
|
|
27
|
-
targetId: 'g-123'
|
|
28
|
-
} as ga4Option);
|
|
29
|
-
|
|
30
|
-
ga4.gtag('event', 'test', {
|
|
31
|
-
'test': 1
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(window.gtag).toBeCalledTimes(3);
|
|
35
|
-
|
|
36
|
-
});
|
|
1
|
+
import {} from '../src/types/global';
|
|
2
|
+
import { ga4 } from '../src/index';
|
|
3
|
+
import { ga4Option } from '../src/ga4/ga4option';
|
|
4
|
+
|
|
5
|
+
describe('test ga4', () => {
|
|
6
|
+
test('init ga4 should call gtag', () => {
|
|
7
|
+
|
|
8
|
+
window.gtag = jest.fn();
|
|
9
|
+
|
|
10
|
+
ga4.init({
|
|
11
|
+
targetId: 'g-123'
|
|
12
|
+
} as ga4Option);
|
|
13
|
+
|
|
14
|
+
ga4.send('test', {
|
|
15
|
+
'test': 1
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
expect(window.gtag).toBeCalledTimes(3);
|
|
19
|
+
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('init ga4 able to use gtag at ga4', () => {
|
|
23
|
+
|
|
24
|
+
window.gtag = jest.fn();
|
|
25
|
+
|
|
26
|
+
ga4.init({
|
|
27
|
+
targetId: 'g-123'
|
|
28
|
+
} as ga4Option);
|
|
29
|
+
|
|
30
|
+
ga4.gtag('event', 'test', {
|
|
31
|
+
'test': 1
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(window.gtag).toBeCalledTimes(3);
|
|
35
|
+
|
|
36
|
+
});
|
|
37
37
|
});
|
package/tsconfig.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"incremental": true,
|
|
4
|
-
"target": "ES2022",
|
|
5
|
-
"outDir": "build/main",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"module": "commonjs",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"inlineSourceMap": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"strict": true,
|
|
14
|
-
"noUnusedLocals": true,
|
|
15
|
-
"noUnusedParameters": true,
|
|
16
|
-
"noImplicitReturns": true,
|
|
17
|
-
"noFallthroughCasesInSwitch": true,
|
|
18
|
-
"traceResolution": false,
|
|
19
|
-
"listEmittedFiles": false,
|
|
20
|
-
"listFiles": false,
|
|
21
|
-
"pretty": true,
|
|
22
|
-
"lib": ["es2017", "dom"],
|
|
23
|
-
"types": ["node"],
|
|
24
|
-
"typeRoots": ["node_modules/@types", "src/types"]
|
|
25
|
-
},
|
|
26
|
-
"include": ["src/**/*.ts"],
|
|
27
|
-
"exclude": ["node_modules/**"],
|
|
28
|
-
"compileOnSave": false
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"incremental": true,
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"outDir": "build/main",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"module": "commonjs",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"inlineSourceMap": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"noUnusedLocals": true,
|
|
15
|
+
"noUnusedParameters": true,
|
|
16
|
+
"noImplicitReturns": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": true,
|
|
18
|
+
"traceResolution": false,
|
|
19
|
+
"listEmittedFiles": false,
|
|
20
|
+
"listFiles": false,
|
|
21
|
+
"pretty": true,
|
|
22
|
+
"lib": ["es2017", "dom"],
|
|
23
|
+
"types": ["node"],
|
|
24
|
+
"typeRoots": ["node_modules/@types", "src/types"]
|
|
25
|
+
},
|
|
26
|
+
"include": ["src/**/*.ts"],
|
|
27
|
+
"exclude": ["node_modules/**"],
|
|
28
|
+
"compileOnSave": false
|
|
29
29
|
}
|
package/tsconfig.module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"target": "esnext",
|
|
5
|
-
"outDir": "build/module",
|
|
6
|
-
"module": "esnext"
|
|
7
|
-
},
|
|
8
|
-
"exclude": [
|
|
9
|
-
"node_modules/**",
|
|
10
|
-
"src/cli/**/*.ts"
|
|
11
|
-
]
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"outDir": "build/module",
|
|
6
|
+
"module": "esnext"
|
|
7
|
+
},
|
|
8
|
+
"exclude": [
|
|
9
|
+
"node_modules/**",
|
|
10
|
+
"src/cli/**/*.ts"
|
|
11
|
+
]
|
|
12
12
|
}
|