@goldstack/utils-track 0.1.17 → 0.2.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 +5 -5
- package/dist/src/utilsTrack.d.ts +13 -13
- package/dist/src/utilsTrack.js +78 -78
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Goldstack JS Tracking Utilities
|
|
2
|
-
|
|
3
|
-
This library allows linking [Google Analytics](https://analytics.google.com/analytics/web/) to React applications.
|
|
4
|
-
|
|
5
|
-
It is used for the [Goldstack Homepage](https://goldstack.party) and [Goldstack Documentation](https://docs.goldstack.party/docs).
|
|
1
|
+
# Goldstack JS Tracking Utilities
|
|
2
|
+
|
|
3
|
+
This library allows linking [Google Analytics](https://analytics.google.com/analytics/web/) to React applications.
|
|
4
|
+
|
|
5
|
+
It is used for the [Goldstack Homepage](https://goldstack.party) and [Goldstack Documentation](https://docs.goldstack.party/docs).
|
package/dist/src/utilsTrack.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export declare let GA_TRACKING_ID: undefined | string;
|
|
2
|
-
export declare const initGtm: (ga_tracking_id: string) => void;
|
|
3
|
-
export declare const pageview: (params: {
|
|
4
|
-
url: string;
|
|
5
|
-
path: string;
|
|
6
|
-
}) => void;
|
|
7
|
-
export declare const event: ({ action, category, label, value }: {
|
|
8
|
-
action: any;
|
|
9
|
-
category: any;
|
|
10
|
-
label: any;
|
|
11
|
-
value: any;
|
|
12
|
-
}) => void;
|
|
13
|
-
export declare const TagFragment: () => JSX.Element;
|
|
1
|
+
export declare let GA_TRACKING_ID: undefined | string;
|
|
2
|
+
export declare const initGtm: (ga_tracking_id: string) => void;
|
|
3
|
+
export declare const pageview: (params: {
|
|
4
|
+
url: string;
|
|
5
|
+
path: string;
|
|
6
|
+
}) => void;
|
|
7
|
+
export declare const event: ({ action, category, label, value }: {
|
|
8
|
+
action: any;
|
|
9
|
+
category: any;
|
|
10
|
+
label: any;
|
|
11
|
+
value: any;
|
|
12
|
+
}) => void;
|
|
13
|
+
export declare const TagFragment: () => JSX.Element;
|
|
14
14
|
//# sourceMappingURL=utilsTrack.d.ts.map
|
package/dist/src/utilsTrack.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TagFragment = exports.event = exports.pageview = exports.initGtm = exports.GA_TRACKING_ID = void 0;
|
|
27
|
-
const react_1 = __importStar(require("react"));
|
|
28
|
-
exports.GA_TRACKING_ID = undefined;
|
|
29
|
-
const initGtm = (ga_tracking_id) => {
|
|
30
|
-
exports.GA_TRACKING_ID = ga_tracking_id;
|
|
31
|
-
};
|
|
32
|
-
exports.initGtm = initGtm;
|
|
33
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
34
|
-
const pageview = (params) => {
|
|
35
|
-
if (!window.gtag) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!exports.GA_TRACKING_ID) {
|
|
39
|
-
throw new Error('Please define tracking id with initGtm()');
|
|
40
|
-
}
|
|
41
|
-
window.gtag('config', exports.GA_TRACKING_ID, {
|
|
42
|
-
page_path: params.path,
|
|
43
|
-
page_location: params.url,
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
exports.pageview = pageview;
|
|
47
|
-
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
|
|
48
|
-
const event = ({ action, category, label, value }) => {
|
|
49
|
-
if (!window.gtag) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (!exports.GA_TRACKING_ID) {
|
|
53
|
-
throw new Error('Please define tracking id with initGtm()');
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
window.gtag('event', action, {
|
|
57
|
-
event_category: category,
|
|
58
|
-
event_label: label,
|
|
59
|
-
value: value,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
console.error(`Cannot log Google Analytics event: ${action} ${category} ${label} ${value}`);
|
|
64
|
-
console.error(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
exports.event = event;
|
|
68
|
-
const TagFragment = () => {
|
|
69
|
-
if (!exports.GA_TRACKING_ID) {
|
|
70
|
-
throw new Error('Please define tracking id with initGtm()');
|
|
71
|
-
}
|
|
72
|
-
return (react_1.default.createElement(react_1.Fragment, null,
|
|
73
|
-
react_1.default.createElement("script", { async: true, src: `https://www.googletagmanager.com/gtag/js?id=${exports.GA_TRACKING_ID}` }),
|
|
74
|
-
react_1.default.createElement("script", { dangerouslySetInnerHTML: {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.TagFragment = exports.event = exports.pageview = exports.initGtm = exports.GA_TRACKING_ID = void 0;
|
|
27
|
+
const react_1 = __importStar(require("react"));
|
|
28
|
+
exports.GA_TRACKING_ID = undefined;
|
|
29
|
+
const initGtm = (ga_tracking_id) => {
|
|
30
|
+
exports.GA_TRACKING_ID = ga_tracking_id;
|
|
31
|
+
};
|
|
32
|
+
exports.initGtm = initGtm;
|
|
33
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
|
34
|
+
const pageview = (params) => {
|
|
35
|
+
if (!window.gtag) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!exports.GA_TRACKING_ID) {
|
|
39
|
+
throw new Error('Please define tracking id with initGtm()');
|
|
40
|
+
}
|
|
41
|
+
window.gtag('config', exports.GA_TRACKING_ID, {
|
|
42
|
+
page_path: params.path,
|
|
43
|
+
page_location: params.url,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.pageview = pageview;
|
|
47
|
+
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
|
|
48
|
+
const event = ({ action, category, label, value }) => {
|
|
49
|
+
if (!window.gtag) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!exports.GA_TRACKING_ID) {
|
|
53
|
+
throw new Error('Please define tracking id with initGtm()');
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
window.gtag('event', action, {
|
|
57
|
+
event_category: category,
|
|
58
|
+
event_label: label,
|
|
59
|
+
value: value,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error(`Cannot log Google Analytics event: ${action} ${category} ${label} ${value}`);
|
|
64
|
+
console.error(e);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.event = event;
|
|
68
|
+
const TagFragment = () => {
|
|
69
|
+
if (!exports.GA_TRACKING_ID) {
|
|
70
|
+
throw new Error('Please define tracking id with initGtm()');
|
|
71
|
+
}
|
|
72
|
+
return (react_1.default.createElement(react_1.Fragment, null,
|
|
73
|
+
react_1.default.createElement("script", { async: true, src: `https://www.googletagmanager.com/gtag/js?id=${exports.GA_TRACKING_ID}` }),
|
|
74
|
+
react_1.default.createElement("script", { dangerouslySetInnerHTML: {
|
|
75
75
|
__html: `
|
|
76
76
|
window.dataLayer = window.dataLayer || [];
|
|
77
77
|
function gtag(){dataLayer.push(arguments);}
|
|
@@ -79,8 +79,8 @@ gtag('js', new Date());
|
|
|
79
79
|
|
|
80
80
|
gtag('config', '${exports.GA_TRACKING_ID}', {
|
|
81
81
|
page_path: window.location.pathname,
|
|
82
|
-
});`,
|
|
83
|
-
} })));
|
|
84
|
-
};
|
|
85
|
-
exports.TagFragment = TagFragment;
|
|
82
|
+
});`,
|
|
83
|
+
} })));
|
|
84
|
+
};
|
|
85
|
+
exports.TagFragment = TagFragment;
|
|
86
86
|
//# sourceMappingURL=utilsTrack.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goldstack/utils-track",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Utilities for including Google Analytics in React application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"goldstack",
|
|
@@ -34,17 +34,17 @@
|
|
|
34
34
|
"version:apply:force": "yarn version $@ && yarn version apply"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"react": "^
|
|
37
|
+
"react": "^18.2.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@goldstack/utils-git": "0.
|
|
41
|
-
"@types/jest": "^
|
|
42
|
-
"@types/node": "^
|
|
43
|
-
"@types/react": "^
|
|
40
|
+
"@goldstack/utils-git": "0.2.0",
|
|
41
|
+
"@types/jest": "^28.1.8",
|
|
42
|
+
"@types/node": "^18.7.13",
|
|
43
|
+
"@types/react": "^18.0.15",
|
|
44
44
|
"jest": "^28.1.0",
|
|
45
45
|
"rimraf": "^3.0.2",
|
|
46
46
|
"ts-jest": "^28.0.2",
|
|
47
|
-
"typescript": "^4.
|
|
47
|
+
"typescript": "^4.7.4"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"main": "dist/src/utilsTrack.js"
|