@ninetailed/experience.js-plugin-google-analytics 7.5.3-beta.2 → 7.5.3-beta.3

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/index.js ADDED
@@ -0,0 +1,77 @@
1
+ import { NinetailedAnalyticsPlugin } from '@ninetailed/experience.js-plugin-analytics';
2
+ import { template } from '@ninetailed/experience.js-shared';
3
+
4
+ /******************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+
19
+ function __awaiter(thisArg, _arguments, P, generator) {
20
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
21
+ return new (P || (P = Promise))(function (resolve, reject) {
22
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
23
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
24
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ }
28
+
29
+ const TEMPLATE_OPTIONS = {
30
+ interpolate: /{{([\s\S]+?)}}/g
31
+ };
32
+ const isGoogleAnalyticsInitialized = () => {
33
+ return typeof window === 'object' && 'gtag' in window &&
34
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
35
+ // @ts-ignore
36
+ typeof window.gtag === 'function';
37
+ };
38
+ class NinetailedGoogleAnalyticsPlugin extends NinetailedAnalyticsPlugin {
39
+ constructor(options = {}) {
40
+ super();
41
+ this.options = options;
42
+ this.name = 'ninetailed:google-analytics';
43
+ }
44
+ onTrackExperience(properties) {
45
+ return Promise.resolve();
46
+ }
47
+ onTrackComponent(properties) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (!isGoogleAnalyticsInitialized()) {
50
+ return;
51
+ }
52
+ const {
53
+ variant,
54
+ audience,
55
+ isPersonalized
56
+ } = properties;
57
+ const action = template(this.options.actionTemplate || 'Has Seen Component - Audience:{{ audience.id }}', {
58
+ component: variant,
59
+ audience
60
+ }, TEMPLATE_OPTIONS.interpolate);
61
+ const label = template(this.options.labelTemplate || '{{ baselineOrVariant }}:{{ component.id }}', {
62
+ component: variant,
63
+ audience,
64
+ baselineOrVariant: isPersonalized ? 'Variant' : 'Baseline'
65
+ }, TEMPLATE_OPTIONS.interpolate);
66
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
67
+ // @ts-ignore
68
+ window.gtag('event', action, {
69
+ category: 'Ninetailed',
70
+ label,
71
+ nonInteraction: true
72
+ });
73
+ });
74
+ }
75
+ }
76
+
77
+ export { NinetailedGoogleAnalyticsPlugin, NinetailedGoogleAnalyticsPlugin as default };
package/package.json CHANGED
@@ -1,24 +1,22 @@
1
1
  {
2
2
  "name": "@ninetailed/experience.js-plugin-google-analytics",
3
- "version": "7.5.3-beta.2",
3
+ "version": "7.5.3-beta.3",
4
+ "devDependencies": {},
4
5
  "description": "Ninetailed SDK plugin for Google Analytics",
5
6
  "license": "MIT",
6
- "keywords": [
7
- "google-analytics",
8
- "ninetailed",
9
- "personalization",
10
- "a/b testing"
11
- ],
12
7
  "repository": {
13
8
  "type": "git",
14
9
  "url": "https://github.com/ninetailed-inc/experience.js.git",
15
10
  "directory": "packages/plugins/google-analytics"
16
11
  },
12
+ "module": "./index.js",
13
+ "main": "./index.cjs",
14
+ "type": "module",
15
+ "types": "./src/index.d.ts",
17
16
  "dependencies": {
18
- "@ninetailed/experience.js": "*",
19
- "@ninetailed/experience.js-plugin-analytics": "*",
20
- "@ninetailed/experience.js-shared": "*"
17
+ "@ninetailed/experience.js": "7.5.3-beta.3",
18
+ "@ninetailed/experience.js-plugin-analytics": "7.5.3-beta.3",
19
+ "@ninetailed/experience.js-shared": "7.5.3-beta.3"
21
20
  },
22
- "module": "./index.esm.js",
23
- "main": "./index.cjs.js"
21
+ "peerDependencies": {}
24
22
  }
package/index.cjs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from "./src/index";
2
- export { default } from "./src/index";
package/index.esm.js DELETED
@@ -1,51 +0,0 @@
1
- import { NinetailedAnalyticsPlugin } from '@ninetailed/experience.js-plugin-analytics';
2
- import { template } from '@ninetailed/experience.js-shared';
3
-
4
- const TEMPLATE_OPTIONS = {
5
- interpolate: /{{([\s\S]+?)}}/g
6
- };
7
- const isGoogleAnalyticsInitialized = () => {
8
- return typeof window === 'object' && 'gtag' in window &&
9
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
10
- // @ts-ignore
11
- typeof window.gtag === 'function';
12
- };
13
- class NinetailedGoogleAnalyticsPlugin extends NinetailedAnalyticsPlugin {
14
- constructor(options = {}) {
15
- super();
16
- this.name = 'ninetailed:google-analytics';
17
- this.options = options;
18
- }
19
- onTrackExperience(properties) {
20
- return Promise.resolve();
21
- }
22
- async onTrackComponent(properties) {
23
- if (!isGoogleAnalyticsInitialized()) {
24
- return;
25
- }
26
- const {
27
- variant,
28
- audience,
29
- isPersonalized
30
- } = properties;
31
- const action = template(this.options.actionTemplate || 'Has Seen Component - Audience:{{ audience.id }}', {
32
- component: variant,
33
- audience
34
- }, TEMPLATE_OPTIONS.interpolate);
35
- const label = template(this.options.labelTemplate || '{{ baselineOrVariant }}:{{ component.id }}', {
36
- component: variant,
37
- audience,
38
- baselineOrVariant: isPersonalized ? 'Variant' : 'Baseline'
39
- }, TEMPLATE_OPTIONS.interpolate);
40
-
41
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
42
- // @ts-ignore
43
- window.gtag('event', action, {
44
- category: 'Ninetailed',
45
- label,
46
- nonInteraction: true
47
- });
48
- }
49
- }
50
-
51
- export { NinetailedGoogleAnalyticsPlugin, NinetailedGoogleAnalyticsPlugin as default };
File without changes