@goldstack/utils-track 0.1.10 → 0.1.11

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.
@@ -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
@@ -1,73 +1,73 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.TagFragment = exports.event = exports.pageview = exports.initGtm = exports.GA_TRACKING_ID = void 0;
23
- const react_1 = __importStar(require("react"));
24
- exports.GA_TRACKING_ID = undefined;
25
- const initGtm = (ga_tracking_id) => {
26
- exports.GA_TRACKING_ID = ga_tracking_id;
27
- };
28
- exports.initGtm = initGtm;
29
- // https://developers.google.com/analytics/devguides/collection/gtagjs/pages
30
- const pageview = (params) => {
31
- if (!window.gtag) {
32
- return;
33
- }
34
- if (!exports.GA_TRACKING_ID) {
35
- throw new Error('Please define tracking id with initGtm()');
36
- }
37
- window.gtag('config', exports.GA_TRACKING_ID, {
38
- page_path: params.path,
39
- page_location: params.url,
40
- });
41
- };
42
- exports.pageview = pageview;
43
- // https://developers.google.com/analytics/devguides/collection/gtagjs/events
44
- const event = ({ action, category, label, value }) => {
45
- if (!window.gtag) {
46
- return;
47
- }
48
- if (!exports.GA_TRACKING_ID) {
49
- throw new Error('Please define tracking id with initGtm()');
50
- }
51
- try {
52
- window.gtag('event', action, {
53
- event_category: category,
54
- event_label: label,
55
- value: value,
56
- });
57
- }
58
- catch (e) {
59
- console.error(`Cannot log Google Analytics event: ${action} ${category} ${label} ${value}`);
60
- console.error(e);
61
- }
62
- };
63
- exports.event = event;
64
- const TagFragment = () => {
65
- if (!exports.GA_TRACKING_ID) {
66
- throw new Error('Please define tracking id with initGtm()');
67
- }
68
- return (react_1.default.createElement(react_1.Fragment, null,
69
- react_1.default.createElement("script", { async: true, src: `https://www.googletagmanager.com/gtag/js?id=${exports.GA_TRACKING_ID}` }),
70
- 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
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.TagFragment = exports.event = exports.pageview = exports.initGtm = exports.GA_TRACKING_ID = void 0;
23
+ const react_1 = __importStar(require("react"));
24
+ exports.GA_TRACKING_ID = undefined;
25
+ const initGtm = (ga_tracking_id) => {
26
+ exports.GA_TRACKING_ID = ga_tracking_id;
27
+ };
28
+ exports.initGtm = initGtm;
29
+ // https://developers.google.com/analytics/devguides/collection/gtagjs/pages
30
+ const pageview = (params) => {
31
+ if (!window.gtag) {
32
+ return;
33
+ }
34
+ if (!exports.GA_TRACKING_ID) {
35
+ throw new Error('Please define tracking id with initGtm()');
36
+ }
37
+ window.gtag('config', exports.GA_TRACKING_ID, {
38
+ page_path: params.path,
39
+ page_location: params.url,
40
+ });
41
+ };
42
+ exports.pageview = pageview;
43
+ // https://developers.google.com/analytics/devguides/collection/gtagjs/events
44
+ const event = ({ action, category, label, value }) => {
45
+ if (!window.gtag) {
46
+ return;
47
+ }
48
+ if (!exports.GA_TRACKING_ID) {
49
+ throw new Error('Please define tracking id with initGtm()');
50
+ }
51
+ try {
52
+ window.gtag('event', action, {
53
+ event_category: category,
54
+ event_label: label,
55
+ value: value,
56
+ });
57
+ }
58
+ catch (e) {
59
+ console.error(`Cannot log Google Analytics event: ${action} ${category} ${label} ${value}`);
60
+ console.error(e);
61
+ }
62
+ };
63
+ exports.event = event;
64
+ const TagFragment = () => {
65
+ if (!exports.GA_TRACKING_ID) {
66
+ throw new Error('Please define tracking id with initGtm()');
67
+ }
68
+ return (react_1.default.createElement(react_1.Fragment, null,
69
+ react_1.default.createElement("script", { async: true, src: `https://www.googletagmanager.com/gtag/js?id=${exports.GA_TRACKING_ID}` }),
70
+ react_1.default.createElement("script", { dangerouslySetInnerHTML: {
71
71
  __html: `
72
72
  window.dataLayer = window.dataLayer || [];
73
73
  function gtag(){dataLayer.push(arguments);}
@@ -75,8 +75,8 @@ gtag('js', new Date());
75
75
 
76
76
  gtag('config', '${exports.GA_TRACKING_ID}', {
77
77
  page_path: window.location.pathname,
78
- });`,
79
- } })));
80
- };
81
- exports.TagFragment = TagFragment;
78
+ });`,
79
+ } })));
80
+ };
81
+ exports.TagFragment = TagFragment;
82
82
  //# sourceMappingURL=utilsTrack.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goldstack/utils-track",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "Utilities for including Google Analytics in React application",
5
5
  "keywords": [
6
6
  "goldstack",
@@ -37,7 +37,7 @@
37
37
  "react": "^17.0.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@goldstack/utils-git": "0.1.28",
40
+ "@goldstack/utils-git": "0.1.29",
41
41
  "@types/jest": "^27.0.2",
42
42
  "@types/node": "^16.11.0",
43
43
  "@types/react": "^16.9.49",