@leancodepl/gtag 8.4.0 → 8.5.1
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 +56 -0
- package/index.cjs.js +14 -1
- package/index.esm.js +14 -1
- package/package.json +34 -3
- package/src/lib/index.d.ts +14 -0
- package/index.esm.d.ts +0 -1
- /package/{index.cjs.d.ts → index.d.ts} +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @leancodepl/gtag
|
|
2
|
+
|
|
3
|
+
Type-safe Google Tag Manager data layer integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @leancodepl/gtag
|
|
9
|
+
# or
|
|
10
|
+
yarn add @leancodepl/gtag
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
### `mkgtag()`
|
|
16
|
+
|
|
17
|
+
Creates a type-safe Google Tag Manager data layer push function.
|
|
18
|
+
|
|
19
|
+
**Returns:** Function that accepts data layer arguments and pushes to GTM
|
|
20
|
+
|
|
21
|
+
## Usage Examples
|
|
22
|
+
|
|
23
|
+
### Basic Event Tracking
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { mkgtag } from '@leancodepl/gtag';
|
|
27
|
+
|
|
28
|
+
const gtag = mkgtag<{ event: 'page_view'; page_title: string }>();
|
|
29
|
+
|
|
30
|
+
gtag({
|
|
31
|
+
event: 'page_view',
|
|
32
|
+
page_title: 'Home Page',
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Custom Events with Callbacks
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { mkgtag } from '@leancodepl/gtag';
|
|
40
|
+
|
|
41
|
+
interface CustomEvent {
|
|
42
|
+
event: 'button_click';
|
|
43
|
+
element_id: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const gtag = mkgtag<CustomEvent>();
|
|
47
|
+
|
|
48
|
+
gtag({
|
|
49
|
+
event: 'button_click',
|
|
50
|
+
element_id: 'signup-button',
|
|
51
|
+
eventCallback: (containerId) => {
|
|
52
|
+
console.log('Event sent to container:', containerId);
|
|
53
|
+
},
|
|
54
|
+
eventTimeout: 2000,
|
|
55
|
+
});
|
|
56
|
+
```
|
package/index.cjs.js
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Creates a type-safe Google Tag Manager data layer push function.
|
|
5
|
+
*
|
|
6
|
+
* Returns a function that pushes events to the GTM data layer with type safety.
|
|
7
|
+
* Handles cases where GTM is not initialized by safely checking for dataLayer existence.
|
|
8
|
+
*
|
|
9
|
+
* @template T - Event object type extending { event: string }
|
|
10
|
+
* @returns Function that accepts data layer arguments and pushes to GTM
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const gtag = mkgtag<{ event: 'purchase'; value: number }>();
|
|
14
|
+
* gtag({ event: 'purchase', value: 29.99 });
|
|
15
|
+
* ```
|
|
16
|
+
*/ function mkgtag() {
|
|
4
17
|
return (dataLayerArguments)=>{
|
|
5
18
|
var _window_dataLayer;
|
|
6
19
|
(_window_dataLayer = window.dataLayer) == null ? void 0 : _window_dataLayer.push(dataLayerArguments);
|
package/index.esm.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a type-safe Google Tag Manager data layer push function.
|
|
3
|
+
*
|
|
4
|
+
* Returns a function that pushes events to the GTM data layer with type safety.
|
|
5
|
+
* Handles cases where GTM is not initialized by safely checking for dataLayer existence.
|
|
6
|
+
*
|
|
7
|
+
* @template T - Event object type extending { event: string }
|
|
8
|
+
* @returns Function that accepts data layer arguments and pushes to GTM
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const gtag = mkgtag<{ event: 'purchase'; value: number }>();
|
|
12
|
+
* gtag({ event: 'purchase', value: 29.99 });
|
|
13
|
+
* ```
|
|
14
|
+
*/ function mkgtag() {
|
|
2
15
|
return (dataLayerArguments)=>{
|
|
3
16
|
var _window_dataLayer;
|
|
4
17
|
(_window_dataLayer = window.dataLayer) == null ? void 0 : _window_dataLayer.push(dataLayerArguments);
|
package/package.json
CHANGED
|
@@ -1,17 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leancodepl/gtag",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public",
|
|
7
|
+
"registry": "https://registry.npmjs.org/"
|
|
8
|
+
},
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18.0.0"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/leancodepl/js_corelibrary.git",
|
|
15
|
+
"directory": "packages/gtag"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/leancodepl/js_corelibrary",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/leancodepl/js_corelibrary/issues"
|
|
20
|
+
},
|
|
21
|
+
"description": "Google Tag Manager integration utilities for web analytics",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"google",
|
|
24
|
+
"analytics",
|
|
25
|
+
"gtag",
|
|
26
|
+
"tracking",
|
|
27
|
+
"typescript",
|
|
28
|
+
"javascript",
|
|
29
|
+
"leancode"
|
|
30
|
+
],
|
|
31
|
+
"author": {
|
|
32
|
+
"name": "LeanCode",
|
|
33
|
+
"url": "https://leancode.co"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
5
36
|
"exports": {
|
|
6
37
|
"./package.json": "./package.json",
|
|
7
38
|
".": {
|
|
8
39
|
"module": "./index.esm.js",
|
|
9
|
-
"types": "./index.
|
|
40
|
+
"types": "./index.d.ts",
|
|
10
41
|
"import": "./index.cjs.mjs",
|
|
11
42
|
"default": "./index.cjs.js"
|
|
12
43
|
}
|
|
13
44
|
},
|
|
14
45
|
"module": "./index.esm.js",
|
|
15
46
|
"main": "./index.cjs.js",
|
|
16
|
-
"types": "./index.
|
|
47
|
+
"types": "./index.d.ts"
|
|
17
48
|
}
|
package/src/lib/index.d.ts
CHANGED
|
@@ -16,6 +16,20 @@ declare global {
|
|
|
16
16
|
}>[];
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a type-safe Google Tag Manager data layer push function.
|
|
21
|
+
*
|
|
22
|
+
* Returns a function that pushes events to the GTM data layer with type safety.
|
|
23
|
+
* Handles cases where GTM is not initialized by safely checking for dataLayer existence.
|
|
24
|
+
*
|
|
25
|
+
* @template T - Event object type extending { event: string }
|
|
26
|
+
* @returns Function that accepts data layer arguments and pushes to GTM
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const gtag = mkgtag<{ event: 'purchase'; value: number }>();
|
|
30
|
+
* gtag({ event: 'purchase', value: 29.99 });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
19
33
|
export declare function mkgtag<T extends {
|
|
20
34
|
event: string;
|
|
21
35
|
}>(): (dataLayerArguments: DataLayerArguments<T>) => void;
|
package/index.esm.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
|
File without changes
|