@technoapple/ga4 1.0.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.
@@ -0,0 +1,31 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [ "main" ]
9
+ pull_request:
10
+ branches: [ "main" ]
11
+
12
+ jobs:
13
+ build:
14
+
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ matrix:
19
+ node-version: [14.x, 16.x, 18.x]
20
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+
22
+ steps:
23
+ - uses: actions/checkout@v3
24
+ - name: Use Node.js ${{ matrix.node-version }}
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: ${{ matrix.node-version }}
28
+ cache: 'npm'
29
+ - run: npm ci
30
+ - run: npm run build --if-present
31
+ - run: npm test
@@ -0,0 +1,2 @@
1
+ # package.json is formatted by package managers, so we ignore it here
2
+ package.json
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 keke78ui9
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # GA4
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ presets: [
3
+ ['@babel/preset-env', {targets: {node: 'current'}}],
4
+ '@babel/preset-typescript',
5
+ ],
6
+ };
package/jest.config.ts ADDED
@@ -0,0 +1,195 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property and type check, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ export default {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ // bail: 0,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/private/var/folders/l_/rkp7zx1x6vj1w6vvn46hfsb40000gn/T/jest_dx",
15
+
16
+ // Automatically clear mock calls, instances, contexts and results before every test
17
+ clearMocks: true,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ collectCoverage: true,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+
25
+ // The directory where Jest should output its coverage files
26
+ coverageDirectory: "coverage",
27
+
28
+ // An array of regexp pattern strings used to skip coverage collection
29
+ // coveragePathIgnorePatterns: [
30
+ // "/node_modules/"
31
+ // ],
32
+
33
+ // Indicates which provider should be used to instrument code for coverage
34
+ // coverageProvider: "babel",
35
+
36
+ // A list of reporter names that Jest uses when writing coverage reports
37
+ // coverageReporters: [
38
+ // "json",
39
+ // "text",
40
+ // "lcov",
41
+ // "clover"
42
+ // ],
43
+
44
+ // An object that configures minimum threshold enforcement for coverage results
45
+ // coverageThreshold: undefined,
46
+
47
+ // A path to a custom dependency extractor
48
+ // dependencyExtractor: undefined,
49
+
50
+ // Make calling deprecated APIs throw helpful error messages
51
+ // errorOnDeprecated: false,
52
+
53
+ // The default configuration for fake timers
54
+ // fakeTimers: {
55
+ // "enableGlobally": false
56
+ // },
57
+
58
+ // Force coverage collection from ignored files using an array of glob patterns
59
+ // forceCoverageMatch: [],
60
+
61
+ // A path to a module which exports an async function that is triggered once before all test suites
62
+ // globalSetup: undefined,
63
+
64
+ // A path to a module which exports an async function that is triggered once after all test suites
65
+ // globalTeardown: undefined,
66
+
67
+ // A set of global variables that need to be available in all test environments
68
+ // globals: {},
69
+
70
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
71
+ // maxWorkers: "50%",
72
+
73
+ // An array of directory names to be searched recursively up from the requiring module's location
74
+ // moduleDirectories: [
75
+ // "node_modules"
76
+ // ],
77
+
78
+ // An array of file extensions your modules use
79
+ // moduleFileExtensions: [
80
+ // "js",
81
+ // "mjs",
82
+ // "cjs",
83
+ // "jsx",
84
+ // "ts",
85
+ // "tsx",
86
+ // "json",
87
+ // "node"
88
+ // ],
89
+
90
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
91
+ // moduleNameMapper: {},
92
+
93
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
94
+ // modulePathIgnorePatterns: [],
95
+
96
+ // Activates notifications for test results
97
+ // notify: false,
98
+
99
+ // An enum that specifies notification mode. Requires { notify: true }
100
+ // notifyMode: "failure-change",
101
+
102
+ // A preset that is used as a base for Jest's configuration
103
+ // preset: undefined,
104
+
105
+ // Run tests from one or more projects
106
+ // projects: undefined,
107
+
108
+ // Use this configuration option to add custom reporters to Jest
109
+ // reporters: undefined,
110
+
111
+ // Automatically reset mock state before every test
112
+ // resetMocks: false,
113
+
114
+ // Reset the module registry before running each individual test
115
+ // resetModules: false,
116
+
117
+ // A path to a custom resolver
118
+ // resolver: undefined,
119
+
120
+ // Automatically restore mock state and implementation before every test
121
+ // restoreMocks: false,
122
+
123
+ // The root directory that Jest should scan for tests and modules within
124
+ // rootDir: undefined,
125
+
126
+ // A list of paths to directories that Jest should use to search for files in
127
+ // roots: [
128
+ // "<rootDir>"
129
+ // ],
130
+
131
+ // Allows you to use a custom runner instead of Jest's default test runner
132
+ // runner: "jest-runner",
133
+
134
+ // The paths to modules that run some code to configure or set up the testing environment before each test
135
+ // setupFiles: [],
136
+
137
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
138
+ // setupFilesAfterEnv: [],
139
+
140
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
141
+ // slowTestThreshold: 5,
142
+
143
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
144
+ // snapshotSerializers: [],
145
+
146
+ // The test environment that will be used for testing
147
+ testEnvironment: "jsdom",
148
+
149
+ // Options that will be passed to the testEnvironment
150
+ testEnvironmentOptions: {},
151
+
152
+ // Adds a location field to test results
153
+ // testLocationInResults: false,
154
+
155
+ // The glob patterns Jest uses to detect test files
156
+ // testMatch: [
157
+ // "**/__tests__/**/*.[jt]s?(x)",
158
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
159
+ // ],
160
+
161
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
162
+ // testPathIgnorePatterns: [
163
+ // "/node_modules/"
164
+ // ],
165
+
166
+ // The regexp pattern or array of patterns that Jest uses to detect test files
167
+ // testRegex: [],
168
+
169
+ // This option allows the use of a custom results processor
170
+ // testResultsProcessor: undefined,
171
+
172
+ // This option allows use of a custom test runner
173
+ // testRunner: "jest-circus/runner",
174
+
175
+ // A map from regular expressions to paths to transformers
176
+ // transform: undefined,
177
+
178
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
179
+ // transformIgnorePatterns: [
180
+ // "/node_modules/",
181
+ // "\\.pnp\\.[^\\/]+$"
182
+ // ],
183
+
184
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
185
+ // unmockedModulePathPatterns: undefined,
186
+
187
+ // Indicates whether each individual test should be reported during the run
188
+ verbose: true,
189
+
190
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
191
+ // watchPathIgnorePatterns: [],
192
+
193
+ // Whether to use watchman for file crawling
194
+ // watchman: true,
195
+ };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@technoapple/ga4",
3
+ "version": "1.0.0",
4
+ "description": "TypeScript Node.js library to support GA4 analytics.",
5
+ "main": "build/main/index.js",
6
+ "typings": "build/main/index.d.ts",
7
+ "module": "build/main/index.js",
8
+ "directories": {
9
+ "test": "test"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc -p tsconfig.json",
13
+ "build:main": "tsc -p tsconfig.json",
14
+ "test": "jest",
15
+ "test:coverage": "jest --coverage --silent",
16
+ "deploy": "run-s build && npm publish",
17
+ "doc:html": "typedoc src/ --exclude **/*.spec.ts --target ES6 --mode file --out build/docs",
18
+ "doc:publish": "gh-pages -m \"[ci skip] Updates\" -d build/docs"
19
+ },
20
+ "keywords": [
21
+ "typescript",
22
+ "reading",
23
+ "speak",
24
+ "html"
25
+ ],
26
+ "repository": "https://github.com/keke78ui9/ga4.git",
27
+ "author": "keke78ui9",
28
+ "license": "ISC",
29
+ "bugs": {
30
+ "url": "https://github.com/keke78ui9/ga4/issues"
31
+ },
32
+ "homepage": "https://github.com/keke78ui9/ga4#readme",
33
+ "devDependencies": {
34
+ "@babel/core": "^7.21.4",
35
+ "@babel/preset-env": "^7.21.4",
36
+ "@babel/preset-typescript": "^7.21.4",
37
+ "@jest/globals": "^29.5.0",
38
+ "@types/jest": "^29.5.0",
39
+ "babel-jest": "^29.5.0",
40
+ "gh-pages": "^5.0.0",
41
+ "jest": "^29.5.0",
42
+ "jest-environment-jsdom": "^29.5.0",
43
+ "jsdom": "^21.1.1",
44
+ "npm-run-all": "^4.1.5",
45
+ "ts-jest": "^29.1.0",
46
+ "ts-node": "^10.9.1",
47
+ "typedoc": "^0.24.6",
48
+ "typescript": "^5.0.4"
49
+ }
50
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * get value from dataLayer
3
+ * @param key key to search from dataLayer
4
+ * @param getLast boolean, false (default) find the first item, true search the last value for the same key
5
+ * @returns return the value if find, otherwise return empty string;
6
+ */
7
+ function get(key:string, getLast?:boolean):string | object {
8
+
9
+ if (window.dataLayer) {
10
+ const data = getLast
11
+ ? window.dataLayer?.findLast((item) => item[key])
12
+ : window.dataLayer?.find((item) => item[key]);
13
+ return data ? data[key] : '';
14
+ }
15
+
16
+ return '';
17
+ }
18
+
19
+ export {get};
package/src/ga4/ga4.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { ga4Option } from "./ga4option";
2
+ import { DataLayerObject } from "../types/dataLayer";
3
+ import { KeyValueParams } from "../types/gtag";
4
+
5
+ class ga4 {
6
+
7
+ private static instance: ga4;
8
+
9
+ private constructor() {
10
+ }
11
+
12
+ public init(option:ga4Option){
13
+ window.dataLayer = window.dataLayer || Array<DataLayerObject>;
14
+ window.gtag = window.gtag || function() {
15
+ window.dataLayer.push(arguments);
16
+ }
17
+ window.gtag('js', new Date());
18
+ window.gtag('config', option.targetId);
19
+ }
20
+
21
+ public static getInstance():ga4 {
22
+ if (!ga4.instance) {
23
+ ga4.instance = new ga4();
24
+ }
25
+ return ga4.instance;
26
+ }
27
+
28
+ public event(eventName:string, eventParameters: KeyValueParams ): boolean {
29
+
30
+ window.gtag('event', eventName, eventParameters);
31
+
32
+ return true;
33
+ }
34
+ }
35
+
36
+ export {ga4};
@@ -0,0 +1,5 @@
1
+ interface ga4Option {
2
+ targetId:string;
3
+ }
4
+
5
+ export {ga4Option};
@@ -0,0 +1,5 @@
1
+ import {ga4} from './ga4';
2
+
3
+ const ga = ga4.getInstance();
4
+
5
+ export {ga};
@@ -0,0 +1,10 @@
1
+ interface KeyValuePair {
2
+ [key:string|number]: any;
3
+ }
4
+
5
+ interface DataLayerObject extends KeyValuePair{
6
+ event?: string;
7
+ value?: string;
8
+ }
9
+
10
+ export {DataLayerObject};
@@ -0,0 +1,16 @@
1
+ import { DataLayerObject } from "./dataLayer";
2
+ import { gtag } from "./gtag";
3
+
4
+ declare global {
5
+
6
+ interface Array<T> {
7
+ findLast(predicate: (value:T, index:number, array:T[]) => unknown, thisArg?:any ): T | undefined
8
+ }
9
+
10
+ interface Window {
11
+ dataLayer: Array<DataLayerObject>;
12
+ gtag:gtag;
13
+ }
14
+ }
15
+
16
+ export {};
@@ -0,0 +1,267 @@
1
+
2
+ /**
3
+ * gtag definition, referenced via here https://developers.google.com/tag-platform/gtagjs/reference
4
+ *
5
+ */
6
+ type requestedFieldCallback = (fieldName:string) => void;
7
+ type eventCallback = () => void;
8
+
9
+ interface KeyValueParams {
10
+ [key:string]: string | number | boolean;
11
+ }
12
+
13
+ interface ConsentParams {
14
+ ad_storage: 'granted' | 'denied';
15
+ analytics_storage: 'granted' | 'denied';
16
+ wait_for_update: number;
17
+ }
18
+
19
+ interface ControlParams {
20
+ groups: string;
21
+ send_to: string;
22
+ event_callback:eventCallback;
23
+ event_timeout:number;
24
+ }
25
+
26
+ interface ItemParameters {
27
+ item_id: string;
28
+ item_name: string;
29
+ affiliation?:string;
30
+ coupon?:string;
31
+ discount?:number;
32
+ index?:number;
33
+ item_brand?:string;
34
+ item_category?:string;
35
+ item_category2?:string;
36
+ item_category3?:string;
37
+ item_category4?:string;
38
+ item_category5?:string;
39
+ item_list_id?:string;
40
+ item_list_name?:string;
41
+ item_variant?:string;
42
+ location_id?:string;
43
+ price?:number;
44
+ quantity?:number;
45
+ }
46
+
47
+ interface PromotionParameters extends ItemParameters {
48
+ creative_name?:string;
49
+ creative_slot?:string;
50
+ promotion_id?:string;
51
+ promotion_name?:string;
52
+ }
53
+
54
+ interface AddPaymentInfo {
55
+ currency: string;
56
+ value: number;
57
+ coupon?:string;
58
+ payment_type?:string;
59
+ items:Array<ItemParameters>;
60
+ }
61
+
62
+ interface AddShippingInfo {
63
+ currency:string;
64
+ value:number;
65
+ coupon?:string;
66
+ shipping_tier?:string;
67
+ items: Array<ItemParameters>;
68
+ }
69
+
70
+ interface AddToCart {
71
+ currency:string;
72
+ value:number;
73
+ items:Array<ItemParameters>;
74
+ }
75
+
76
+ interface AddToWishlistOrRemoveFromCart {
77
+ currency:string;
78
+ value:number;
79
+ items:Array<ItemParameters>;
80
+ }
81
+
82
+ interface BeginCheckout {
83
+ currency:string;
84
+ value:number;
85
+ coupon?:string;
86
+ items:Array<ItemParameters>;
87
+ }
88
+
89
+ interface EarnVirtualCurrency {
90
+ earn_virtual_currency?:string;
91
+ value?:number;
92
+ }
93
+
94
+ interface Exception {
95
+ description?:string;
96
+ fatal?:boolean;
97
+ }
98
+
99
+ interface GenerateLead {
100
+ currency:string;
101
+ value:number;
102
+ }
103
+
104
+ interface LevelEnd {
105
+ level_name?: string;
106
+ success?:boolean;
107
+ }
108
+
109
+ interface LevelUp {
110
+ level?: number;
111
+ character?:string;
112
+ }
113
+
114
+ interface PageView {
115
+ page_location?: string;
116
+ client_id?: string;
117
+ language?: string;
118
+ page_encoding?: string;
119
+ page_title?: string;
120
+ user_agent?: string;
121
+ }
122
+
123
+ interface PostScore {
124
+ score:number;
125
+ level?:number;
126
+ character?:string;
127
+ }
128
+
129
+ interface PurchaseRefund {
130
+ currency:string;
131
+ transaction_id:string;
132
+ value:number;
133
+ coupon?:string;
134
+ shipping?:number;
135
+ tax?:number;
136
+ items:Array<ItemParameters>;
137
+ }
138
+
139
+ interface SelectContent {
140
+ content_type?:string;
141
+ content_id?:string;
142
+ }
143
+
144
+ interface SelectItem {
145
+ item_list_id?:string;
146
+ item_list_name?:string;
147
+ items:Array<ItemParameters>;
148
+ }
149
+
150
+ interface SelectPromotion {
151
+ creative_name?:string;
152
+ creative_slot?:string;
153
+ promotion_id?:string;
154
+ promotion_name?:string;
155
+ items:Array<PromotionParameters>;
156
+ }
157
+
158
+ interface Share {
159
+ method?:string;
160
+ content_type?:string;
161
+ item_id?:string;
162
+ }
163
+
164
+ interface SignUp {
165
+ method?:string;
166
+ }
167
+
168
+ interface SpendVirtualCurrency {
169
+ value:number;
170
+ virtual_currency_name:string;
171
+ item_name:string;
172
+ }
173
+
174
+ interface UnlockAchievement {
175
+ achievement_id:string;
176
+ }
177
+
178
+ interface ViewCart {
179
+ currency:string;
180
+ value:number;
181
+ items: Array<ItemParameters>
182
+ }
183
+
184
+ interface ViewItem {
185
+ currency:string;
186
+ value:number;
187
+ items:Array<ItemParameters>;
188
+ }
189
+
190
+ interface ViewItemList {
191
+ item_list_id?:string;
192
+ item_list_name?:string;
193
+ items:Array<ItemParameters>;
194
+ }
195
+
196
+ interface ViewPromotion {
197
+ creative_name?:string;
198
+ creative_slot?:string;
199
+ promotion_id?:string;
200
+ promotion_name?:string;
201
+ items:Array<PromotionParameters>;
202
+ }
203
+
204
+ interface ViewSearchResults {
205
+ search_term?:string;
206
+ }
207
+
208
+ interface JoinGroup {
209
+ group_id?:string;
210
+ }
211
+
212
+ interface LevelStart {
213
+ level_name:string
214
+ }
215
+
216
+ interface Login {
217
+ login?:string;
218
+ }
219
+
220
+ interface Search {
221
+ search_term:string
222
+ }
223
+
224
+ interface gtag {
225
+ (command:'config', TARGET_ID:string, configInfo?: KeyValueParams | ControlParams): void;
226
+ (command:'js', value: Date):void;
227
+ (command:'get', TARGET_ID:string, fieldName:string, callbackFunc: requestedFieldCallback): void;
228
+ (command:'set', customerParameter: KeyValueParams | ControlParams):void;
229
+ (command:'event', eventName:'add_payment_info', customerParameter:AddPaymentInfo | KeyValueParams | ControlParams):void;
230
+ (command:'event', eventName:'add_shipping_info', customerParameter:AddShippingInfo | KeyValueParams | ControlParams):void;
231
+ (command:'event', eventName:'add_to_cart', customerParameter:AddToCart | KeyValueParams | ControlParams):void;
232
+ (command:'event', eventName:'add_to_wishlist', customerParameter:AddToWishlistOrRemoveFromCart | KeyValueParams | ControlParams):void;
233
+ (command:'event', eventName:'begin_checkout', customerParameter:AddToWishlistOrRemoveFromCart | KeyValueParams | ControlParams):void;
234
+ (command:'event', eventName:'earn_virtual_currency', customerParameter:EarnVirtualCurrency | KeyValueParams | ControlParams):void;
235
+ (command:'event', eventName:'exception', customerParameter:Exception | KeyValueParams | ControlParams):void;
236
+ (command:'event', eventName:'generate_lead', customerParameter:GenerateLead | KeyValueParams | ControlParams):void;
237
+ (command:'event', eventName:'join_group', customerParameter:JoinGroup | KeyValueParams | ControlParams):void;
238
+ (command:'event', eventName:'level_end', customerParameter:LevelEnd | KeyValueParams | ControlParams):void;
239
+ (command:'event', eventName:'level_start', customerParameter:LevelStart | KeyValueParams | ControlParams):void;
240
+ (command:'event', eventName:'level_up', customerParameter:LevelUp | KeyValueParams | ControlParams):void;
241
+ (command:'event', eventName:'login', customerParameter:Login | KeyValueParams | ControlParams):void;
242
+ (command:'event', eventName:'page_view', customerParameter:PageView | KeyValueParams | ControlParams):void;
243
+ (command:'event', eventName:'post_score', customerParameter:PostScore | KeyValueParams | ControlParams):void;
244
+ (command:'event', eventName:'purchase', customerParameter:PurchaseRefund | KeyValueParams | ControlParams):void;
245
+ (command:'event', eventName:'refund', customerParameter:PurchaseRefund | KeyValueParams | ControlParams):void;
246
+ (command:'event', eventName:'remove_from_cart', customerParameter:AddToWishlistOrRemoveFromCart | KeyValueParams | ControlParams):void;
247
+ (command:'event', eventName:'search', customerParameter:Search | KeyValueParams | ControlParams):void;
248
+ (command:'event', eventName:'select_content', customerParameter:SelectContent | KeyValueParams | ControlParams):void;
249
+ (command:'event', eventName:'select_item', customerParameter:SelectItem | KeyValueParams | ControlParams):void;
250
+ (command:'event', eventName:'select_promotion', customerParameter:SelectPromotion | KeyValueParams | ControlParams):void;
251
+ (command:'event', eventName:'share', customerParameter:Share | KeyValueParams | ControlParams):void;
252
+ (command:'event', eventName:'sign_up', customerParameter:SignUp | KeyValueParams | ControlParams):void;
253
+ (command:'event', eventName:'spend_virtual_currency', customerParameter:SpendVirtualCurrency | KeyValueParams | ControlParams):void;
254
+ (command:'event', eventName:'tutorial_begin', customerParameter:KeyValueParams | ControlParams):void;
255
+ (command:'event', eventName:'tutorial_complete', customerParameter:KeyValueParams | ControlParams):void;
256
+ (command:'event', eventName:'unlock_achievement', customerParameter:UnlockAchievement | KeyValueParams | ControlParams):void;
257
+ (command:'event', eventName:'view_cart', customerParameter:ViewCart | KeyValueParams | ControlParams):void;
258
+ (command:'event', eventName:'view_item', customerParameter:ViewItem | KeyValueParams | ControlParams):void;
259
+ (command:'event', eventName:'view_item_list', customerParameter:ViewItemList | KeyValueParams | ControlParams):void;
260
+ (command:'event', eventName:'view_promotion', customerParameter:ViewPromotion | KeyValueParams | ControlParams):void;
261
+ (command:'event', eventName:'view_search_results', customerParameter:ViewSearchResults | KeyValueParams | ControlParams):void;
262
+ (command:'event', eventName:string, customerParameter:KeyValueParams | ControlParams):void;
263
+ (command:'consent', consent:'default', customerParameter:ConsentParams | KeyValueParams):void;
264
+ (command:'consent', consent:'update', customerParameter:ConsentParams | KeyValueParams):void;
265
+ }
266
+
267
+ export {gtag, KeyValueParams};
@@ -0,0 +1,20 @@
1
+ import {} from '../src/types/global';
2
+ import {get} from '../src/dataLayer';
3
+
4
+ describe('test dataLayer get function', () => {
5
+ test('', () => {
6
+
7
+ window.dataLayer = window.dataLayer || [];
8
+
9
+ window.dataLayer.push({
10
+ 'test': 1
11
+ });
12
+ window.dataLayer.push({
13
+ 'test': 11
14
+ });
15
+
16
+ const result = get('test');
17
+ expect(result).toBe(1);
18
+
19
+ });
20
+ });
@@ -0,0 +1,21 @@
1
+ import {} from '../src/types/global';
2
+ import { ga} from '../src/ga4/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
+ ga.init({
11
+ targetId: 'g-123'
12
+ } as ga4Option);
13
+
14
+ ga.event('test', {
15
+ 'test': 1
16
+ });
17
+
18
+ expect(window.gtag).toBeCalledTimes(3);
19
+
20
+ });
21
+ });
package/tsconfig.json ADDED
@@ -0,0 +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
29
+ }
@@ -0,0 +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
+ ]
12
+ }