@blotoutio/providers-rtb-house-sdk 1.40.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 ADDED
@@ -0,0 +1,3 @@
1
+ # RTB House Provider SDK
2
+
3
+ SDK package for RTB House provider integration. This package handles browser-side tracking for RTB House.
package/index.cjs.js ADDED
@@ -0,0 +1,171 @@
1
+ 'use strict';
2
+
3
+ const packageName = 'rtbHouse';
4
+
5
+ const init = ({ manifest }) => {
6
+ if (!manifest.variables ||
7
+ !manifest.variables['accountId'] ||
8
+ typeof window === 'undefined' ||
9
+ typeof document === 'undefined') {
10
+ return;
11
+ }
12
+ // Only inject the RTB House creative CDN snippet (rtbhEvents)
13
+ const accountId = manifest.variables['accountId'];
14
+ try {
15
+ const dn = 'rtbhEvents';
16
+ if (!window[dn]) {
17
+ window[dn] = [];
18
+ }
19
+ window[dn].push({ eventType: 'init', value: accountId, dc: '' });
20
+ // Insert the creativecdn script directly (avoid duplicate insertion by using a script id)
21
+ const firstScript = document.getElementsByTagName('script')[0];
22
+ const scriptId = `rtbh-creative-${accountId}`;
23
+ if (!document.getElementById(scriptId)) {
24
+ const c = document.createElement('script');
25
+ c.async = true;
26
+ c.id = scriptId;
27
+ c.src = `https://tags.creativecdn.com/${accountId}.js`;
28
+ if (firstScript && firstScript.parentNode) {
29
+ firstScript.parentNode.insertBefore(c, firstScript);
30
+ }
31
+ }
32
+ }
33
+ catch (e) {
34
+ console.warn('RTB House creative CDN injection failed', e);
35
+ }
36
+ };
37
+
38
+ const canLog = () => {
39
+ try {
40
+ return localStorage.getItem('edgeTagDebug') === '1';
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ };
46
+ const prefix = `[EdgeTag]`;
47
+ const logger = {
48
+ log: (...args) => {
49
+ if (canLog()) {
50
+ console.log(prefix, ...args);
51
+ }
52
+ },
53
+ error: (...args) => {
54
+ if (canLog()) {
55
+ console.error(prefix, ...args);
56
+ }
57
+ },
58
+ info: (...args) => {
59
+ if (canLog()) {
60
+ console.info(prefix, ...args);
61
+ }
62
+ },
63
+ trace: (...args) => {
64
+ if (canLog()) {
65
+ console.trace(prefix, ...args);
66
+ }
67
+ },
68
+ };
69
+
70
+ const ensureRtbh = () => {
71
+ if (!Array.isArray(window.rtbhEvents)) {
72
+ window.rtbhEvents = [];
73
+ }
74
+ return window.rtbhEvents;
75
+ };
76
+ const getOfferId = (item) => { var _a, _b, _c; return String((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.variantId) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.id) !== null && _b !== void 0 ? _b : item === null || item === void 0 ? void 0 : item.sku) !== null && _c !== void 0 ? _c : 'unknown'); };
77
+ const getOfferIds = (items, limit = 5) => (Array.isArray(items) ? items : []).slice(0, limit).map((i) => getOfferId(i));
78
+ const tag = ({ data, eventName, userId }) => {
79
+ // RTB House: push events to `window.rtbhEvents` queue (ensure it's created)
80
+ const getUid = () => {
81
+ if (!userId) {
82
+ return 'unknown';
83
+ }
84
+ return String(userId);
85
+ };
86
+ try {
87
+ const rtbh = ensureRtbh();
88
+ const uid = getUid();
89
+ switch (eventName) {
90
+ case 'PageView':
91
+ {
92
+ const isHome = window.location.pathname === '/' || window.location.pathname === '';
93
+ const page = isHome ? 'home' : 'placebo';
94
+ rtbh.push({ eventType: page }, { eventType: 'uid', id: uid });
95
+ }
96
+ break;
97
+ case 'ViewContent': {
98
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
99
+ if (Array.isArray(contents) && contents.length > 0) {
100
+ const item = contents[0];
101
+ const offerId = getOfferId(item);
102
+ rtbh.push({ eventType: 'offer', offerId }, { eventType: 'uid', id: uid });
103
+ }
104
+ break;
105
+ }
106
+ case 'AddToCart': {
107
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
108
+ if (Array.isArray(contents) && contents.length > 0) {
109
+ const events = contents.map((c) => ({
110
+ eventType: 'basketadd',
111
+ offerId: getOfferId(c),
112
+ }));
113
+ events.push({ eventType: 'uid', id: uid });
114
+ rtbh.push(...events);
115
+ }
116
+ break;
117
+ }
118
+ case 'InitiateCheckout': {
119
+ rtbh.push({ eventType: 'startorder' }, { eventType: 'uid', id: uid });
120
+ break;
121
+ }
122
+ case 'Purchase': {
123
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
124
+ const orderId = data === null || data === void 0 ? void 0 : data['orderId'];
125
+ const value = data === null || data === void 0 ? void 0 : data['value'];
126
+ const currency = (data === null || data === void 0 ? void 0 : data['currency']) || 'USD';
127
+ if (orderId && Array.isArray(contents) && contents.length > 0) {
128
+ const offerIds = getOfferIds(contents, 50);
129
+ const valueStr = String(Number(value || 0).toFixed(2));
130
+ rtbh.push({
131
+ eventType: 'conversion',
132
+ conversionClass: 'order',
133
+ conversionSubClass: 'purchase',
134
+ conversionId: orderId,
135
+ offerIds,
136
+ conversionValue: valueStr,
137
+ conversionCurrency: currency,
138
+ }, { eventType: 'uid', id: uid });
139
+ }
140
+ break;
141
+ }
142
+ default: {
143
+ logger.log(`[${packageName}] ${eventName} not supported`);
144
+ }
145
+ }
146
+ }
147
+ catch (e) {
148
+ logger.error(e);
149
+ }
150
+ return {};
151
+ };
152
+
153
+ // eslint-disable-next-line @nx/enforce-module-boundaries
154
+ const data = {
155
+ name: packageName,
156
+ tag,
157
+ init,
158
+ };
159
+ try {
160
+ if (typeof window !== 'undefined') {
161
+ if (!window.edgetagProviders) {
162
+ window.edgetagProviders = [];
163
+ }
164
+ window.edgetagProviders.push(data);
165
+ }
166
+ }
167
+ catch {
168
+ // No window
169
+ }
170
+
171
+ module.exports = data;
package/index.js ADDED
@@ -0,0 +1,174 @@
1
+ var ProvidersRtbHouseSdk = (function () {
2
+ 'use strict';
3
+
4
+ const packageName = 'rtbHouse';
5
+
6
+ const init = ({ manifest }) => {
7
+ if (!manifest.variables ||
8
+ !manifest.variables['accountId'] ||
9
+ typeof window === 'undefined' ||
10
+ typeof document === 'undefined') {
11
+ return;
12
+ }
13
+ // Only inject the RTB House creative CDN snippet (rtbhEvents)
14
+ const accountId = manifest.variables['accountId'];
15
+ try {
16
+ const dn = 'rtbhEvents';
17
+ if (!window[dn]) {
18
+ window[dn] = [];
19
+ }
20
+ window[dn].push({ eventType: 'init', value: accountId, dc: '' });
21
+ // Insert the creativecdn script directly (avoid duplicate insertion by using a script id)
22
+ const firstScript = document.getElementsByTagName('script')[0];
23
+ const scriptId = `rtbh-creative-${accountId}`;
24
+ if (!document.getElementById(scriptId)) {
25
+ const c = document.createElement('script');
26
+ c.async = true;
27
+ c.id = scriptId;
28
+ c.src = `https://tags.creativecdn.com/${accountId}.js`;
29
+ if (firstScript && firstScript.parentNode) {
30
+ firstScript.parentNode.insertBefore(c, firstScript);
31
+ }
32
+ }
33
+ }
34
+ catch (e) {
35
+ console.warn('RTB House creative CDN injection failed', e);
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 ensureRtbh = () => {
72
+ if (!Array.isArray(window.rtbhEvents)) {
73
+ window.rtbhEvents = [];
74
+ }
75
+ return window.rtbhEvents;
76
+ };
77
+ const getOfferId = (item) => { var _a, _b, _c; return String((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.variantId) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.id) !== null && _b !== void 0 ? _b : item === null || item === void 0 ? void 0 : item.sku) !== null && _c !== void 0 ? _c : 'unknown'); };
78
+ const getOfferIds = (items, limit = 5) => (Array.isArray(items) ? items : []).slice(0, limit).map((i) => getOfferId(i));
79
+ const tag = ({ data, eventName, userId }) => {
80
+ // RTB House: push events to `window.rtbhEvents` queue (ensure it's created)
81
+ const getUid = () => {
82
+ if (!userId) {
83
+ return 'unknown';
84
+ }
85
+ return String(userId);
86
+ };
87
+ try {
88
+ const rtbh = ensureRtbh();
89
+ const uid = getUid();
90
+ switch (eventName) {
91
+ case 'PageView':
92
+ {
93
+ const isHome = window.location.pathname === '/' || window.location.pathname === '';
94
+ const page = isHome ? 'home' : 'placebo';
95
+ rtbh.push({ eventType: page }, { eventType: 'uid', id: uid });
96
+ }
97
+ break;
98
+ case 'ViewContent': {
99
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
100
+ if (Array.isArray(contents) && contents.length > 0) {
101
+ const item = contents[0];
102
+ const offerId = getOfferId(item);
103
+ rtbh.push({ eventType: 'offer', offerId }, { eventType: 'uid', id: uid });
104
+ }
105
+ break;
106
+ }
107
+ case 'AddToCart': {
108
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
109
+ if (Array.isArray(contents) && contents.length > 0) {
110
+ const events = contents.map((c) => ({
111
+ eventType: 'basketadd',
112
+ offerId: getOfferId(c),
113
+ }));
114
+ events.push({ eventType: 'uid', id: uid });
115
+ rtbh.push(...events);
116
+ }
117
+ break;
118
+ }
119
+ case 'InitiateCheckout': {
120
+ rtbh.push({ eventType: 'startorder' }, { eventType: 'uid', id: uid });
121
+ break;
122
+ }
123
+ case 'Purchase': {
124
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
125
+ const orderId = data === null || data === void 0 ? void 0 : data['orderId'];
126
+ const value = data === null || data === void 0 ? void 0 : data['value'];
127
+ const currency = (data === null || data === void 0 ? void 0 : data['currency']) || 'USD';
128
+ if (orderId && Array.isArray(contents) && contents.length > 0) {
129
+ const offerIds = getOfferIds(contents, 50);
130
+ const valueStr = String(Number(value || 0).toFixed(2));
131
+ rtbh.push({
132
+ eventType: 'conversion',
133
+ conversionClass: 'order',
134
+ conversionSubClass: 'purchase',
135
+ conversionId: orderId,
136
+ offerIds,
137
+ conversionValue: valueStr,
138
+ conversionCurrency: currency,
139
+ }, { eventType: 'uid', id: uid });
140
+ }
141
+ break;
142
+ }
143
+ default: {
144
+ logger.log(`[${packageName}] ${eventName} not supported`);
145
+ }
146
+ }
147
+ }
148
+ catch (e) {
149
+ logger.error(e);
150
+ }
151
+ return {};
152
+ };
153
+
154
+ // eslint-disable-next-line @nx/enforce-module-boundaries
155
+ const data = {
156
+ name: packageName,
157
+ tag,
158
+ init,
159
+ };
160
+ try {
161
+ if (typeof window !== 'undefined') {
162
+ if (!window.edgetagProviders) {
163
+ window.edgetagProviders = [];
164
+ }
165
+ window.edgetagProviders.push(data);
166
+ }
167
+ }
168
+ catch {
169
+ // No window
170
+ }
171
+
172
+ return data;
173
+
174
+ })();
package/index.mjs ADDED
@@ -0,0 +1,169 @@
1
+ const packageName = 'rtbHouse';
2
+
3
+ const init = ({ manifest }) => {
4
+ if (!manifest.variables ||
5
+ !manifest.variables['accountId'] ||
6
+ typeof window === 'undefined' ||
7
+ typeof document === 'undefined') {
8
+ return;
9
+ }
10
+ // Only inject the RTB House creative CDN snippet (rtbhEvents)
11
+ const accountId = manifest.variables['accountId'];
12
+ try {
13
+ const dn = 'rtbhEvents';
14
+ if (!window[dn]) {
15
+ window[dn] = [];
16
+ }
17
+ window[dn].push({ eventType: 'init', value: accountId, dc: '' });
18
+ // Insert the creativecdn script directly (avoid duplicate insertion by using a script id)
19
+ const firstScript = document.getElementsByTagName('script')[0];
20
+ const scriptId = `rtbh-creative-${accountId}`;
21
+ if (!document.getElementById(scriptId)) {
22
+ const c = document.createElement('script');
23
+ c.async = true;
24
+ c.id = scriptId;
25
+ c.src = `https://tags.creativecdn.com/${accountId}.js`;
26
+ if (firstScript && firstScript.parentNode) {
27
+ firstScript.parentNode.insertBefore(c, firstScript);
28
+ }
29
+ }
30
+ }
31
+ catch (e) {
32
+ console.warn('RTB House creative CDN injection failed', e);
33
+ }
34
+ };
35
+
36
+ const canLog = () => {
37
+ try {
38
+ return localStorage.getItem('edgeTagDebug') === '1';
39
+ }
40
+ catch {
41
+ return false;
42
+ }
43
+ };
44
+ const prefix = `[EdgeTag]`;
45
+ const logger = {
46
+ log: (...args) => {
47
+ if (canLog()) {
48
+ console.log(prefix, ...args);
49
+ }
50
+ },
51
+ error: (...args) => {
52
+ if (canLog()) {
53
+ console.error(prefix, ...args);
54
+ }
55
+ },
56
+ info: (...args) => {
57
+ if (canLog()) {
58
+ console.info(prefix, ...args);
59
+ }
60
+ },
61
+ trace: (...args) => {
62
+ if (canLog()) {
63
+ console.trace(prefix, ...args);
64
+ }
65
+ },
66
+ };
67
+
68
+ const ensureRtbh = () => {
69
+ if (!Array.isArray(window.rtbhEvents)) {
70
+ window.rtbhEvents = [];
71
+ }
72
+ return window.rtbhEvents;
73
+ };
74
+ const getOfferId = (item) => { var _a, _b, _c; return String((_c = (_b = (_a = item === null || item === void 0 ? void 0 : item.variantId) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.id) !== null && _b !== void 0 ? _b : item === null || item === void 0 ? void 0 : item.sku) !== null && _c !== void 0 ? _c : 'unknown'); };
75
+ const getOfferIds = (items, limit = 5) => (Array.isArray(items) ? items : []).slice(0, limit).map((i) => getOfferId(i));
76
+ const tag = ({ data, eventName, userId }) => {
77
+ // RTB House: push events to `window.rtbhEvents` queue (ensure it's created)
78
+ const getUid = () => {
79
+ if (!userId) {
80
+ return 'unknown';
81
+ }
82
+ return String(userId);
83
+ };
84
+ try {
85
+ const rtbh = ensureRtbh();
86
+ const uid = getUid();
87
+ switch (eventName) {
88
+ case 'PageView':
89
+ {
90
+ const isHome = window.location.pathname === '/' || window.location.pathname === '';
91
+ const page = isHome ? 'home' : 'placebo';
92
+ rtbh.push({ eventType: page }, { eventType: 'uid', id: uid });
93
+ }
94
+ break;
95
+ case 'ViewContent': {
96
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
97
+ if (Array.isArray(contents) && contents.length > 0) {
98
+ const item = contents[0];
99
+ const offerId = getOfferId(item);
100
+ rtbh.push({ eventType: 'offer', offerId }, { eventType: 'uid', id: uid });
101
+ }
102
+ break;
103
+ }
104
+ case 'AddToCart': {
105
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
106
+ if (Array.isArray(contents) && contents.length > 0) {
107
+ const events = contents.map((c) => ({
108
+ eventType: 'basketadd',
109
+ offerId: getOfferId(c),
110
+ }));
111
+ events.push({ eventType: 'uid', id: uid });
112
+ rtbh.push(...events);
113
+ }
114
+ break;
115
+ }
116
+ case 'InitiateCheckout': {
117
+ rtbh.push({ eventType: 'startorder' }, { eventType: 'uid', id: uid });
118
+ break;
119
+ }
120
+ case 'Purchase': {
121
+ const contents = data === null || data === void 0 ? void 0 : data['contents'];
122
+ const orderId = data === null || data === void 0 ? void 0 : data['orderId'];
123
+ const value = data === null || data === void 0 ? void 0 : data['value'];
124
+ const currency = (data === null || data === void 0 ? void 0 : data['currency']) || 'USD';
125
+ if (orderId && Array.isArray(contents) && contents.length > 0) {
126
+ const offerIds = getOfferIds(contents, 50);
127
+ const valueStr = String(Number(value || 0).toFixed(2));
128
+ rtbh.push({
129
+ eventType: 'conversion',
130
+ conversionClass: 'order',
131
+ conversionSubClass: 'purchase',
132
+ conversionId: orderId,
133
+ offerIds,
134
+ conversionValue: valueStr,
135
+ conversionCurrency: currency,
136
+ }, { eventType: 'uid', id: uid });
137
+ }
138
+ break;
139
+ }
140
+ default: {
141
+ logger.log(`[${packageName}] ${eventName} not supported`);
142
+ }
143
+ }
144
+ }
145
+ catch (e) {
146
+ logger.error(e);
147
+ }
148
+ return {};
149
+ };
150
+
151
+ // eslint-disable-next-line @nx/enforce-module-boundaries
152
+ const data = {
153
+ name: packageName,
154
+ tag,
155
+ init,
156
+ };
157
+ try {
158
+ if (typeof window !== 'undefined') {
159
+ if (!window.edgetagProviders) {
160
+ window.edgetagProviders = [];
161
+ }
162
+ window.edgetagProviders.push(data);
163
+ }
164
+ }
165
+ catch {
166
+ // No window
167
+ }
168
+
169
+ export { data as default };
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@blotoutio/providers-rtb-house-sdk",
3
+ "version": "1.40.0",
4
+ "description": "RTB House 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
+ }