@blotoutio/providers-tatari-sdk 1.16.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 ADDED
@@ -0,0 +1,11 @@
1
+ # providers-tatari-sdk
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build providers-tatari-sdk` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test providers-tatari-sdk` to execute the unit tests via [Jest](https://jestjs.io).
package/index.cjs.js ADDED
@@ -0,0 +1,191 @@
1
+ 'use strict';
2
+
3
+ const packageName = 'tatari';
4
+
5
+ const getCookieValue = (key) => {
6
+ var _a;
7
+ try {
8
+ if (!document || !document.cookie) {
9
+ return '';
10
+ }
11
+ const cookies = parseCookies(document.cookie);
12
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
13
+ }
14
+ catch {
15
+ return '';
16
+ }
17
+ };
18
+ const parseCookies = (cookie) => {
19
+ return Object.fromEntries(cookie
20
+ .split(/;\s+/)
21
+ .map((r) => r.split('=').map((str) => str.trim()))
22
+ .map(([cookieKey, ...cookieValues]) => {
23
+ const cookieValue = cookieValues.join('=');
24
+ if (!cookieKey) {
25
+ return [];
26
+ }
27
+ let decodedValue = '';
28
+ if (cookieValue) {
29
+ try {
30
+ decodedValue = decodeURIComponent(cookieValue);
31
+ }
32
+ catch (e) {
33
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
34
+ decodedValue = cookieValue;
35
+ }
36
+ }
37
+ return [cookieKey, decodedValue];
38
+ }));
39
+ };
40
+
41
+ const canLog = () => {
42
+ try {
43
+ return localStorage.getItem('edgeTagDebug') === '1';
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ };
49
+ const prefix = `[EdgeTag]`;
50
+ const logger = {
51
+ log: (...args) => {
52
+ if (canLog()) {
53
+ console.log(prefix, ...args);
54
+ }
55
+ },
56
+ error: (...args) => {
57
+ if (canLog()) {
58
+ console.error(prefix, ...args);
59
+ }
60
+ },
61
+ info: (...args) => {
62
+ if (canLog()) {
63
+ console.info(prefix, ...args);
64
+ }
65
+ },
66
+ trace: (...args) => {
67
+ if (canLog()) {
68
+ console.trace(prefix, ...args);
69
+ }
70
+ },
71
+ };
72
+
73
+ const initSnippet = (token) => {
74
+ var _a;
75
+ if (typeof window == 'undefined' ||
76
+ typeof document == 'undefined' ||
77
+ window.tatari) {
78
+ return;
79
+ }
80
+ try {
81
+ const tatari = (window.tatari = (window.tatari || []));
82
+ tatari.init = function (a, b) {
83
+ const e = function (t, n) {
84
+ tatari[n] = function () {
85
+ // eslint-disable-next-line
86
+ t.push([n].concat(Array.prototype.slice.call(arguments, 0)));
87
+ };
88
+ };
89
+ 'track pageview identify'.split(' ').forEach(function (t) {
90
+ e(tatari, t);
91
+ });
92
+ tatari._i = a;
93
+ tatari.config = b;
94
+ };
95
+ tatari.version = '1.2.17';
96
+ const n = document.createElement('script');
97
+ n.type = 'text/javascript';
98
+ n.async = !0;
99
+ n.src = `https://d2hrivdxn8ekm8.cloudfront.net/tag-manager/${token}-latest.js`;
100
+ const e = document.getElementsByTagName('script')[0];
101
+ (_a = e.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, e);
102
+ tatari.init(token);
103
+ }
104
+ catch (t) {
105
+ console.error(t);
106
+ }
107
+ };
108
+ const init = ({ manifest, userId }) => {
109
+ var _a, _b;
110
+ if (!window ||
111
+ !manifest.variables ||
112
+ manifest.variables['enableBrowser'] !== '1' ||
113
+ !manifest.variables['token']) {
114
+ return;
115
+ }
116
+ initSnippet(manifest.variables['token']);
117
+ const tatariUserId = getCookieValue(((_a = window.tatari) === null || _a === void 0 ? void 0 : _a.userCookieName) || 'tatari-user-cookie');
118
+ if (!tatariUserId) {
119
+ (_b = window.tatari) === null || _b === void 0 ? void 0 : _b.identify(userId);
120
+ }
121
+ };
122
+
123
+ const getEventData = (data) => {
124
+ const eventData = {};
125
+ if (!data) {
126
+ return eventData;
127
+ }
128
+ const parsedValue = Number.parseFloat(data['value']);
129
+ if (!Number.isNaN(parsedValue)) {
130
+ eventData['value'] = parsedValue;
131
+ }
132
+ if (data['currency']) {
133
+ eventData['currency'] = data['currency'];
134
+ }
135
+ if (data['orderId']) {
136
+ eventData['orderId'] = data['orderId'];
137
+ }
138
+ return eventData;
139
+ };
140
+ const handleTag = ({ data, eventName, manifestVariables, }) => {
141
+ var _a;
142
+ if (typeof window == 'undefined' ||
143
+ !eventName ||
144
+ !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['token']) ||
145
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['enableBrowser']) !== '1') {
146
+ return;
147
+ }
148
+ let mapping = new Map();
149
+ try {
150
+ mapping = new Map(JSON.parse(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['mappedEvents']));
151
+ }
152
+ catch (error) {
153
+ logger.error('Could not parse mapped events', error);
154
+ }
155
+ const conversionEventName = mapping.get(eventName);
156
+ if (!conversionEventName) {
157
+ return;
158
+ }
159
+ const eventData = getEventData(data);
160
+ (_a = window.tatari) === null || _a === void 0 ? void 0 : _a.track(conversionEventName, eventData);
161
+ };
162
+
163
+ const tag = ({ data, eventName, manifestVariables }) => {
164
+ const payload = {
165
+ sdkVersion: "1.16.1" ,
166
+ };
167
+ if (window.tatari && manifestVariables['enableBrowser'] === '1') {
168
+ handleTag({ data, eventName, manifestVariables });
169
+ }
170
+ return payload;
171
+ };
172
+
173
+ // eslint-disable-next-line @nx/enforce-module-boundaries
174
+ const data = {
175
+ name: packageName,
176
+ init,
177
+ tag,
178
+ };
179
+ try {
180
+ if (window) {
181
+ if (!window.edgetagProviders) {
182
+ window.edgetagProviders = [];
183
+ }
184
+ window.edgetagProviders.push(data);
185
+ }
186
+ }
187
+ catch {
188
+ // No window
189
+ }
190
+
191
+ module.exports = data;
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ declare module '@blotoutio/providers-tatari-sdk'
package/index.js ADDED
@@ -0,0 +1,194 @@
1
+ var ProvidersTatariSdk = (function () {
2
+ 'use strict';
3
+
4
+ const packageName = 'tatari';
5
+
6
+ const getCookieValue = (key) => {
7
+ var _a;
8
+ try {
9
+ if (!document || !document.cookie) {
10
+ return '';
11
+ }
12
+ const cookies = parseCookies(document.cookie);
13
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
14
+ }
15
+ catch {
16
+ return '';
17
+ }
18
+ };
19
+ const parseCookies = (cookie) => {
20
+ return Object.fromEntries(cookie
21
+ .split(/;\s+/)
22
+ .map((r) => r.split('=').map((str) => str.trim()))
23
+ .map(([cookieKey, ...cookieValues]) => {
24
+ const cookieValue = cookieValues.join('=');
25
+ if (!cookieKey) {
26
+ return [];
27
+ }
28
+ let decodedValue = '';
29
+ if (cookieValue) {
30
+ try {
31
+ decodedValue = decodeURIComponent(cookieValue);
32
+ }
33
+ catch (e) {
34
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
35
+ decodedValue = cookieValue;
36
+ }
37
+ }
38
+ return [cookieKey, decodedValue];
39
+ }));
40
+ };
41
+
42
+ const canLog = () => {
43
+ try {
44
+ return localStorage.getItem('edgeTagDebug') === '1';
45
+ }
46
+ catch {
47
+ return false;
48
+ }
49
+ };
50
+ const prefix = `[EdgeTag]`;
51
+ const logger = {
52
+ log: (...args) => {
53
+ if (canLog()) {
54
+ console.log(prefix, ...args);
55
+ }
56
+ },
57
+ error: (...args) => {
58
+ if (canLog()) {
59
+ console.error(prefix, ...args);
60
+ }
61
+ },
62
+ info: (...args) => {
63
+ if (canLog()) {
64
+ console.info(prefix, ...args);
65
+ }
66
+ },
67
+ trace: (...args) => {
68
+ if (canLog()) {
69
+ console.trace(prefix, ...args);
70
+ }
71
+ },
72
+ };
73
+
74
+ const initSnippet = (token) => {
75
+ var _a;
76
+ if (typeof window == 'undefined' ||
77
+ typeof document == 'undefined' ||
78
+ window.tatari) {
79
+ return;
80
+ }
81
+ try {
82
+ const tatari = (window.tatari = (window.tatari || []));
83
+ tatari.init = function (a, b) {
84
+ const e = function (t, n) {
85
+ tatari[n] = function () {
86
+ // eslint-disable-next-line
87
+ t.push([n].concat(Array.prototype.slice.call(arguments, 0)));
88
+ };
89
+ };
90
+ 'track pageview identify'.split(' ').forEach(function (t) {
91
+ e(tatari, t);
92
+ });
93
+ tatari._i = a;
94
+ tatari.config = b;
95
+ };
96
+ tatari.version = '1.2.17';
97
+ const n = document.createElement('script');
98
+ n.type = 'text/javascript';
99
+ n.async = !0;
100
+ n.src = `https://d2hrivdxn8ekm8.cloudfront.net/tag-manager/${token}-latest.js`;
101
+ const e = document.getElementsByTagName('script')[0];
102
+ (_a = e.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, e);
103
+ tatari.init(token);
104
+ }
105
+ catch (t) {
106
+ console.error(t);
107
+ }
108
+ };
109
+ const init = ({ manifest, userId }) => {
110
+ var _a, _b;
111
+ if (!window ||
112
+ !manifest.variables ||
113
+ manifest.variables['enableBrowser'] !== '1' ||
114
+ !manifest.variables['token']) {
115
+ return;
116
+ }
117
+ initSnippet(manifest.variables['token']);
118
+ const tatariUserId = getCookieValue(((_a = window.tatari) === null || _a === void 0 ? void 0 : _a.userCookieName) || 'tatari-user-cookie');
119
+ if (!tatariUserId) {
120
+ (_b = window.tatari) === null || _b === void 0 ? void 0 : _b.identify(userId);
121
+ }
122
+ };
123
+
124
+ const getEventData = (data) => {
125
+ const eventData = {};
126
+ if (!data) {
127
+ return eventData;
128
+ }
129
+ const parsedValue = Number.parseFloat(data['value']);
130
+ if (!Number.isNaN(parsedValue)) {
131
+ eventData['value'] = parsedValue;
132
+ }
133
+ if (data['currency']) {
134
+ eventData['currency'] = data['currency'];
135
+ }
136
+ if (data['orderId']) {
137
+ eventData['orderId'] = data['orderId'];
138
+ }
139
+ return eventData;
140
+ };
141
+ const handleTag = ({ data, eventName, manifestVariables, }) => {
142
+ var _a;
143
+ if (typeof window == 'undefined' ||
144
+ !eventName ||
145
+ !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['token']) ||
146
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['enableBrowser']) !== '1') {
147
+ return;
148
+ }
149
+ let mapping = new Map();
150
+ try {
151
+ mapping = new Map(JSON.parse(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['mappedEvents']));
152
+ }
153
+ catch (error) {
154
+ logger.error('Could not parse mapped events', error);
155
+ }
156
+ const conversionEventName = mapping.get(eventName);
157
+ if (!conversionEventName) {
158
+ return;
159
+ }
160
+ const eventData = getEventData(data);
161
+ (_a = window.tatari) === null || _a === void 0 ? void 0 : _a.track(conversionEventName, eventData);
162
+ };
163
+
164
+ const tag = ({ data, eventName, manifestVariables }) => {
165
+ const payload = {
166
+ sdkVersion: "1.16.1" ,
167
+ };
168
+ if (window.tatari && manifestVariables['enableBrowser'] === '1') {
169
+ handleTag({ data, eventName, manifestVariables });
170
+ }
171
+ return payload;
172
+ };
173
+
174
+ // eslint-disable-next-line @nx/enforce-module-boundaries
175
+ const data = {
176
+ name: packageName,
177
+ init,
178
+ tag,
179
+ };
180
+ try {
181
+ if (window) {
182
+ if (!window.edgetagProviders) {
183
+ window.edgetagProviders = [];
184
+ }
185
+ window.edgetagProviders.push(data);
186
+ }
187
+ }
188
+ catch {
189
+ // No window
190
+ }
191
+
192
+ return data;
193
+
194
+ })();
package/index.mjs ADDED
@@ -0,0 +1,189 @@
1
+ const packageName = 'tatari';
2
+
3
+ const getCookieValue = (key) => {
4
+ var _a;
5
+ try {
6
+ if (!document || !document.cookie) {
7
+ return '';
8
+ }
9
+ const cookies = parseCookies(document.cookie);
10
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
11
+ }
12
+ catch {
13
+ return '';
14
+ }
15
+ };
16
+ const parseCookies = (cookie) => {
17
+ return Object.fromEntries(cookie
18
+ .split(/;\s+/)
19
+ .map((r) => r.split('=').map((str) => str.trim()))
20
+ .map(([cookieKey, ...cookieValues]) => {
21
+ const cookieValue = cookieValues.join('=');
22
+ if (!cookieKey) {
23
+ return [];
24
+ }
25
+ let decodedValue = '';
26
+ if (cookieValue) {
27
+ try {
28
+ decodedValue = decodeURIComponent(cookieValue);
29
+ }
30
+ catch (e) {
31
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
32
+ decodedValue = cookieValue;
33
+ }
34
+ }
35
+ return [cookieKey, decodedValue];
36
+ }));
37
+ };
38
+
39
+ const canLog = () => {
40
+ try {
41
+ return localStorage.getItem('edgeTagDebug') === '1';
42
+ }
43
+ catch {
44
+ return false;
45
+ }
46
+ };
47
+ const prefix = `[EdgeTag]`;
48
+ const logger = {
49
+ log: (...args) => {
50
+ if (canLog()) {
51
+ console.log(prefix, ...args);
52
+ }
53
+ },
54
+ error: (...args) => {
55
+ if (canLog()) {
56
+ console.error(prefix, ...args);
57
+ }
58
+ },
59
+ info: (...args) => {
60
+ if (canLog()) {
61
+ console.info(prefix, ...args);
62
+ }
63
+ },
64
+ trace: (...args) => {
65
+ if (canLog()) {
66
+ console.trace(prefix, ...args);
67
+ }
68
+ },
69
+ };
70
+
71
+ const initSnippet = (token) => {
72
+ var _a;
73
+ if (typeof window == 'undefined' ||
74
+ typeof document == 'undefined' ||
75
+ window.tatari) {
76
+ return;
77
+ }
78
+ try {
79
+ const tatari = (window.tatari = (window.tatari || []));
80
+ tatari.init = function (a, b) {
81
+ const e = function (t, n) {
82
+ tatari[n] = function () {
83
+ // eslint-disable-next-line
84
+ t.push([n].concat(Array.prototype.slice.call(arguments, 0)));
85
+ };
86
+ };
87
+ 'track pageview identify'.split(' ').forEach(function (t) {
88
+ e(tatari, t);
89
+ });
90
+ tatari._i = a;
91
+ tatari.config = b;
92
+ };
93
+ tatari.version = '1.2.17';
94
+ const n = document.createElement('script');
95
+ n.type = 'text/javascript';
96
+ n.async = !0;
97
+ n.src = `https://d2hrivdxn8ekm8.cloudfront.net/tag-manager/${token}-latest.js`;
98
+ const e = document.getElementsByTagName('script')[0];
99
+ (_a = e.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(n, e);
100
+ tatari.init(token);
101
+ }
102
+ catch (t) {
103
+ console.error(t);
104
+ }
105
+ };
106
+ const init = ({ manifest, userId }) => {
107
+ var _a, _b;
108
+ if (!window ||
109
+ !manifest.variables ||
110
+ manifest.variables['enableBrowser'] !== '1' ||
111
+ !manifest.variables['token']) {
112
+ return;
113
+ }
114
+ initSnippet(manifest.variables['token']);
115
+ const tatariUserId = getCookieValue(((_a = window.tatari) === null || _a === void 0 ? void 0 : _a.userCookieName) || 'tatari-user-cookie');
116
+ if (!tatariUserId) {
117
+ (_b = window.tatari) === null || _b === void 0 ? void 0 : _b.identify(userId);
118
+ }
119
+ };
120
+
121
+ const getEventData = (data) => {
122
+ const eventData = {};
123
+ if (!data) {
124
+ return eventData;
125
+ }
126
+ const parsedValue = Number.parseFloat(data['value']);
127
+ if (!Number.isNaN(parsedValue)) {
128
+ eventData['value'] = parsedValue;
129
+ }
130
+ if (data['currency']) {
131
+ eventData['currency'] = data['currency'];
132
+ }
133
+ if (data['orderId']) {
134
+ eventData['orderId'] = data['orderId'];
135
+ }
136
+ return eventData;
137
+ };
138
+ const handleTag = ({ data, eventName, manifestVariables, }) => {
139
+ var _a;
140
+ if (typeof window == 'undefined' ||
141
+ !eventName ||
142
+ !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['token']) ||
143
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['enableBrowser']) !== '1') {
144
+ return;
145
+ }
146
+ let mapping = new Map();
147
+ try {
148
+ mapping = new Map(JSON.parse(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['mappedEvents']));
149
+ }
150
+ catch (error) {
151
+ logger.error('Could not parse mapped events', error);
152
+ }
153
+ const conversionEventName = mapping.get(eventName);
154
+ if (!conversionEventName) {
155
+ return;
156
+ }
157
+ const eventData = getEventData(data);
158
+ (_a = window.tatari) === null || _a === void 0 ? void 0 : _a.track(conversionEventName, eventData);
159
+ };
160
+
161
+ const tag = ({ data, eventName, manifestVariables }) => {
162
+ const payload = {
163
+ sdkVersion: "1.16.1" ,
164
+ };
165
+ if (window.tatari && manifestVariables['enableBrowser'] === '1') {
166
+ handleTag({ data, eventName, manifestVariables });
167
+ }
168
+ return payload;
169
+ };
170
+
171
+ // eslint-disable-next-line @nx/enforce-module-boundaries
172
+ const data = {
173
+ name: packageName,
174
+ init,
175
+ tag,
176
+ };
177
+ try {
178
+ if (window) {
179
+ if (!window.edgetagProviders) {
180
+ window.edgetagProviders = [];
181
+ }
182
+ window.edgetagProviders.push(data);
183
+ }
184
+ }
185
+ catch {
186
+ // No window
187
+ }
188
+
189
+ export { data as default };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@blotoutio/providers-tatari-sdk",
3
+ "version": "1.16.1",
4
+ "description": "tatari Browser SDK for EdgeTag",
5
+ "author": "Blotout",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/blotoutio/edgetag-sdk",
8
+ "publishConfig": {
9
+ "access": "public"
10
+ },
11
+ "main": "./index.cjs.js",
12
+ "module": "./index.mjs",
13
+ "types": "./index.d.ts",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
17
+ },
18
+ "files": [
19
+ "index.js",
20
+ "index.d.ts",
21
+ "index.cjs.js",
22
+ "index.mjs",
23
+ "package.json",
24
+ "README.md"
25
+ ]
26
+ }