@blotoutio/providers-reddit-sdk 0.39.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,11 @@
1
+ # providers-reddit-sdk
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build providers-reddit-sdk` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test providers-reddit-sdk` to execute the unit tests via [Jest](https://jestjs.io).
package/index.cjs.js ADDED
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ const packageName = 'reddit';
4
+ const sdkUrl = 'https://www.redditstatic.com/ads/pixel.js';
5
+
6
+ // eslint-disable-next-line @nx/enforce-module-boundaries
7
+ const snippet = () => {
8
+ if (!window || !document || window.rdt) {
9
+ return;
10
+ }
11
+ const p = (window.rdt = function () {
12
+ p.sendEvent
13
+ ? // eslint-disable-next-line prefer-spread,prefer-rest-params
14
+ p.sendEvent.apply(p, arguments)
15
+ : // eslint-disable-next-line prefer-rest-params
16
+ p.callQueue.push(arguments);
17
+ });
18
+ p.callQueue = [];
19
+ const element = document.createElement('script');
20
+ element.src = sdkUrl;
21
+ element.async = !0;
22
+ const script = document.getElementsByTagName('script')[0];
23
+ if (script && script.parentNode) {
24
+ script.parentNode.insertBefore(element, script);
25
+ }
26
+ };
27
+ const init = ({ manifest, userId }) => {
28
+ if (!manifest.variables ||
29
+ !manifest.variables['pixelId'] ||
30
+ manifest.variables['enableBrowser'] !== '1') {
31
+ return;
32
+ }
33
+ snippet();
34
+ if (!window.rdt) {
35
+ return;
36
+ }
37
+ window['rdt']('init', manifest.variables['pixelId'], {
38
+ externalId: userId,
39
+ });
40
+ };
41
+
42
+ const eventNameMap = {
43
+ PageView: 'PageVisit',
44
+ ViewContent: 'ViewContent',
45
+ Search: 'Search',
46
+ AddToWishlist: 'AddToWishlist',
47
+ AddToCart: 'AddToCart',
48
+ Purchase: 'Purchase',
49
+ Lead: 'Lead',
50
+ CompleteRegistration: 'SignUp',
51
+ };
52
+ const getRedditEventName = (eventName) => {
53
+ if (eventName in eventNameMap) {
54
+ return {
55
+ tracking_type: eventNameMap[eventName],
56
+ };
57
+ }
58
+ return {
59
+ tracking_type: 'Custom',
60
+ custom_event_name: eventName,
61
+ };
62
+ };
63
+ const getEventData = (data, eventName) => {
64
+ const payload = {
65
+ app: 'Blotout',
66
+ };
67
+ if (eventName === 'Lead' ||
68
+ eventName === 'SignUp' ||
69
+ eventName === 'Custom' ||
70
+ eventName === 'Purchase' ||
71
+ eventName === 'AddToCart' ||
72
+ eventName === 'AddToWishlist') {
73
+ if (data['value'] || data['value'] === 0) {
74
+ payload['value'] = data['value'];
75
+ }
76
+ if (data['currency']) {
77
+ payload['currency'] = data['currency'];
78
+ }
79
+ }
80
+ if (eventName === 'Custom' ||
81
+ eventName === 'Purchase' ||
82
+ eventName === 'AddToCart' ||
83
+ eventName === 'AddToWishlist') {
84
+ if (data['contents'] && Array.isArray(data['contents'])) {
85
+ payload['itemCount'] = data['contents'].length;
86
+ }
87
+ }
88
+ if (data['contents'] && Array.isArray(data['contents'])) {
89
+ payload['products'] = data['contents'].map((content) => {
90
+ var _a;
91
+ return ({
92
+ id: (_a = content.id) === null || _a === void 0 ? void 0 : _a.toString(),
93
+ name: content.title,
94
+ category: content.category || '',
95
+ });
96
+ });
97
+ }
98
+ return payload;
99
+ };
100
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
101
+ const payload = {
102
+ sdkVersion: "0.39.0" ,
103
+ };
104
+ if (window.rdt && manifestVariables['enableBrowser'] === '1') {
105
+ const { tracking_type, custom_event_name } = getRedditEventName(eventName);
106
+ const eventData = getEventData(data, tracking_type);
107
+ if (tracking_type === 'Custom') {
108
+ eventData['customEventName'] = custom_event_name;
109
+ }
110
+ window.rdt('track', tracking_type, { ...eventData, conversionId: eventId });
111
+ }
112
+ return payload;
113
+ };
114
+
115
+ // eslint-disable-next-line @nx/enforce-module-boundaries
116
+ const data = {
117
+ name: packageName,
118
+ tag,
119
+ init,
120
+ };
121
+ try {
122
+ if (window) {
123
+ if (!window.edgetagProviders) {
124
+ window.edgetagProviders = [];
125
+ }
126
+ window.edgetagProviders.push(data);
127
+ }
128
+ }
129
+ catch {
130
+ // No window
131
+ }
132
+
133
+ module.exports = data;
package/index.js ADDED
@@ -0,0 +1,136 @@
1
+ var ProvidersRedditSdk = (function () {
2
+ 'use strict';
3
+
4
+ const packageName = 'reddit';
5
+ const sdkUrl = 'https://www.redditstatic.com/ads/pixel.js';
6
+
7
+ // eslint-disable-next-line @nx/enforce-module-boundaries
8
+ const snippet = () => {
9
+ if (!window || !document || window.rdt) {
10
+ return;
11
+ }
12
+ const p = (window.rdt = function () {
13
+ p.sendEvent
14
+ ? // eslint-disable-next-line prefer-spread,prefer-rest-params
15
+ p.sendEvent.apply(p, arguments)
16
+ : // eslint-disable-next-line prefer-rest-params
17
+ p.callQueue.push(arguments);
18
+ });
19
+ p.callQueue = [];
20
+ const element = document.createElement('script');
21
+ element.src = sdkUrl;
22
+ element.async = !0;
23
+ const script = document.getElementsByTagName('script')[0];
24
+ if (script && script.parentNode) {
25
+ script.parentNode.insertBefore(element, script);
26
+ }
27
+ };
28
+ const init = ({ manifest, userId }) => {
29
+ if (!manifest.variables ||
30
+ !manifest.variables['pixelId'] ||
31
+ manifest.variables['enableBrowser'] !== '1') {
32
+ return;
33
+ }
34
+ snippet();
35
+ if (!window.rdt) {
36
+ return;
37
+ }
38
+ window['rdt']('init', manifest.variables['pixelId'], {
39
+ externalId: userId,
40
+ });
41
+ };
42
+
43
+ const eventNameMap = {
44
+ PageView: 'PageVisit',
45
+ ViewContent: 'ViewContent',
46
+ Search: 'Search',
47
+ AddToWishlist: 'AddToWishlist',
48
+ AddToCart: 'AddToCart',
49
+ Purchase: 'Purchase',
50
+ Lead: 'Lead',
51
+ CompleteRegistration: 'SignUp',
52
+ };
53
+ const getRedditEventName = (eventName) => {
54
+ if (eventName in eventNameMap) {
55
+ return {
56
+ tracking_type: eventNameMap[eventName],
57
+ };
58
+ }
59
+ return {
60
+ tracking_type: 'Custom',
61
+ custom_event_name: eventName,
62
+ };
63
+ };
64
+ const getEventData = (data, eventName) => {
65
+ const payload = {
66
+ app: 'Blotout',
67
+ };
68
+ if (eventName === 'Lead' ||
69
+ eventName === 'SignUp' ||
70
+ eventName === 'Custom' ||
71
+ eventName === 'Purchase' ||
72
+ eventName === 'AddToCart' ||
73
+ eventName === 'AddToWishlist') {
74
+ if (data['value'] || data['value'] === 0) {
75
+ payload['value'] = data['value'];
76
+ }
77
+ if (data['currency']) {
78
+ payload['currency'] = data['currency'];
79
+ }
80
+ }
81
+ if (eventName === 'Custom' ||
82
+ eventName === 'Purchase' ||
83
+ eventName === 'AddToCart' ||
84
+ eventName === 'AddToWishlist') {
85
+ if (data['contents'] && Array.isArray(data['contents'])) {
86
+ payload['itemCount'] = data['contents'].length;
87
+ }
88
+ }
89
+ if (data['contents'] && Array.isArray(data['contents'])) {
90
+ payload['products'] = data['contents'].map((content) => {
91
+ var _a;
92
+ return ({
93
+ id: (_a = content.id) === null || _a === void 0 ? void 0 : _a.toString(),
94
+ name: content.title,
95
+ category: content.category || '',
96
+ });
97
+ });
98
+ }
99
+ return payload;
100
+ };
101
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
102
+ const payload = {
103
+ sdkVersion: "0.39.0" ,
104
+ };
105
+ if (window.rdt && manifestVariables['enableBrowser'] === '1') {
106
+ const { tracking_type, custom_event_name } = getRedditEventName(eventName);
107
+ const eventData = getEventData(data, tracking_type);
108
+ if (tracking_type === 'Custom') {
109
+ eventData['customEventName'] = custom_event_name;
110
+ }
111
+ window.rdt('track', tracking_type, { ...eventData, conversionId: eventId });
112
+ }
113
+ return payload;
114
+ };
115
+
116
+ // eslint-disable-next-line @nx/enforce-module-boundaries
117
+ const data = {
118
+ name: packageName,
119
+ tag,
120
+ init,
121
+ };
122
+ try {
123
+ if (window) {
124
+ if (!window.edgetagProviders) {
125
+ window.edgetagProviders = [];
126
+ }
127
+ window.edgetagProviders.push(data);
128
+ }
129
+ }
130
+ catch {
131
+ // No window
132
+ }
133
+
134
+ return data;
135
+
136
+ })();
package/index.mjs ADDED
@@ -0,0 +1,131 @@
1
+ const packageName = 'reddit';
2
+ const sdkUrl = 'https://www.redditstatic.com/ads/pixel.js';
3
+
4
+ // eslint-disable-next-line @nx/enforce-module-boundaries
5
+ const snippet = () => {
6
+ if (!window || !document || window.rdt) {
7
+ return;
8
+ }
9
+ const p = (window.rdt = function () {
10
+ p.sendEvent
11
+ ? // eslint-disable-next-line prefer-spread,prefer-rest-params
12
+ p.sendEvent.apply(p, arguments)
13
+ : // eslint-disable-next-line prefer-rest-params
14
+ p.callQueue.push(arguments);
15
+ });
16
+ p.callQueue = [];
17
+ const element = document.createElement('script');
18
+ element.src = sdkUrl;
19
+ element.async = !0;
20
+ const script = document.getElementsByTagName('script')[0];
21
+ if (script && script.parentNode) {
22
+ script.parentNode.insertBefore(element, script);
23
+ }
24
+ };
25
+ const init = ({ manifest, userId }) => {
26
+ if (!manifest.variables ||
27
+ !manifest.variables['pixelId'] ||
28
+ manifest.variables['enableBrowser'] !== '1') {
29
+ return;
30
+ }
31
+ snippet();
32
+ if (!window.rdt) {
33
+ return;
34
+ }
35
+ window['rdt']('init', manifest.variables['pixelId'], {
36
+ externalId: userId,
37
+ });
38
+ };
39
+
40
+ const eventNameMap = {
41
+ PageView: 'PageVisit',
42
+ ViewContent: 'ViewContent',
43
+ Search: 'Search',
44
+ AddToWishlist: 'AddToWishlist',
45
+ AddToCart: 'AddToCart',
46
+ Purchase: 'Purchase',
47
+ Lead: 'Lead',
48
+ CompleteRegistration: 'SignUp',
49
+ };
50
+ const getRedditEventName = (eventName) => {
51
+ if (eventName in eventNameMap) {
52
+ return {
53
+ tracking_type: eventNameMap[eventName],
54
+ };
55
+ }
56
+ return {
57
+ tracking_type: 'Custom',
58
+ custom_event_name: eventName,
59
+ };
60
+ };
61
+ const getEventData = (data, eventName) => {
62
+ const payload = {
63
+ app: 'Blotout',
64
+ };
65
+ if (eventName === 'Lead' ||
66
+ eventName === 'SignUp' ||
67
+ eventName === 'Custom' ||
68
+ eventName === 'Purchase' ||
69
+ eventName === 'AddToCart' ||
70
+ eventName === 'AddToWishlist') {
71
+ if (data['value'] || data['value'] === 0) {
72
+ payload['value'] = data['value'];
73
+ }
74
+ if (data['currency']) {
75
+ payload['currency'] = data['currency'];
76
+ }
77
+ }
78
+ if (eventName === 'Custom' ||
79
+ eventName === 'Purchase' ||
80
+ eventName === 'AddToCart' ||
81
+ eventName === 'AddToWishlist') {
82
+ if (data['contents'] && Array.isArray(data['contents'])) {
83
+ payload['itemCount'] = data['contents'].length;
84
+ }
85
+ }
86
+ if (data['contents'] && Array.isArray(data['contents'])) {
87
+ payload['products'] = data['contents'].map((content) => {
88
+ var _a;
89
+ return ({
90
+ id: (_a = content.id) === null || _a === void 0 ? void 0 : _a.toString(),
91
+ name: content.title,
92
+ category: content.category || '',
93
+ });
94
+ });
95
+ }
96
+ return payload;
97
+ };
98
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
99
+ const payload = {
100
+ sdkVersion: "0.39.0" ,
101
+ };
102
+ if (window.rdt && manifestVariables['enableBrowser'] === '1') {
103
+ const { tracking_type, custom_event_name } = getRedditEventName(eventName);
104
+ const eventData = getEventData(data, tracking_type);
105
+ if (tracking_type === 'Custom') {
106
+ eventData['customEventName'] = custom_event_name;
107
+ }
108
+ window.rdt('track', tracking_type, { ...eventData, conversionId: eventId });
109
+ }
110
+ return payload;
111
+ };
112
+
113
+ // eslint-disable-next-line @nx/enforce-module-boundaries
114
+ const data = {
115
+ name: packageName,
116
+ tag,
117
+ init,
118
+ };
119
+ try {
120
+ if (window) {
121
+ if (!window.edgetagProviders) {
122
+ window.edgetagProviders = [];
123
+ }
124
+ window.edgetagProviders.push(data);
125
+ }
126
+ }
127
+ catch {
128
+ // No window
129
+ }
130
+
131
+ export { data as default };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@blotoutio/providers-reddit-sdk",
3
+ "version": "0.39.0",
4
+ "description": "Reddit 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
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
16
+ },
17
+ "files": [
18
+ "index.js",
19
+ "index.cjs.js",
20
+ "index.mjs",
21
+ "package.json",
22
+ "README.md"
23
+ ]
24
+ }