@segment/analytics-browser-actions-reddit-pixel 1.1.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.
Files changed (75) hide show
  1. package/README.md +31 -0
  2. package/dist/cjs/fields.d.ts +8 -0
  3. package/dist/cjs/fields.js +473 -0
  4. package/dist/cjs/fields.js.map +1 -0
  5. package/dist/cjs/generated-types.d.ts +4 -0
  6. package/dist/cjs/generated-types.js +3 -0
  7. package/dist/cjs/generated-types.js.map +1 -0
  8. package/dist/cjs/index.d.ts +11 -0
  9. package/dist/cjs/index.js +140 -0
  10. package/dist/cjs/index.js.map +1 -0
  11. package/dist/cjs/init-pixel.d.ts +1 -0
  12. package/dist/cjs/init-pixel.js +30 -0
  13. package/dist/cjs/init-pixel.js.map +1 -0
  14. package/dist/cjs/reportCustomWebEvent/generated-types.d.ts +25 -0
  15. package/dist/cjs/reportCustomWebEvent/generated-types.js +3 -0
  16. package/dist/cjs/reportCustomWebEvent/generated-types.js.map +1 -0
  17. package/dist/cjs/reportCustomWebEvent/index.d.ts +6 -0
  18. package/dist/cjs/reportCustomWebEvent/index.js +24 -0
  19. package/dist/cjs/reportCustomWebEvent/index.js.map +1 -0
  20. package/dist/cjs/reportWebEvent/generated-types.d.ts +25 -0
  21. package/dist/cjs/reportWebEvent/generated-types.js +3 -0
  22. package/dist/cjs/reportWebEvent/generated-types.js.map +1 -0
  23. package/dist/cjs/reportWebEvent/index.d.ts +6 -0
  24. package/dist/cjs/reportWebEvent/index.js +24 -0
  25. package/dist/cjs/reportWebEvent/index.js.map +1 -0
  26. package/dist/cjs/types.d.ts +26 -0
  27. package/dist/cjs/types.js +3 -0
  28. package/dist/cjs/types.js.map +1 -0
  29. package/dist/cjs/utils.d.ts +6 -0
  30. package/dist/cjs/utils.js +36 -0
  31. package/dist/cjs/utils.js.map +1 -0
  32. package/dist/esm/fields.d.ts +8 -0
  33. package/dist/esm/fields.js +470 -0
  34. package/dist/esm/fields.js.map +1 -0
  35. package/dist/esm/generated-types.d.ts +4 -0
  36. package/dist/esm/generated-types.js +2 -0
  37. package/dist/esm/generated-types.js.map +1 -0
  38. package/dist/esm/index.d.ts +11 -0
  39. package/dist/esm/index.js +136 -0
  40. package/dist/esm/index.js.map +1 -0
  41. package/dist/esm/init-pixel.d.ts +1 -0
  42. package/dist/esm/init-pixel.js +26 -0
  43. package/dist/esm/init-pixel.js.map +1 -0
  44. package/dist/esm/reportCustomWebEvent/generated-types.d.ts +25 -0
  45. package/dist/esm/reportCustomWebEvent/generated-types.js +2 -0
  46. package/dist/esm/reportCustomWebEvent/generated-types.js.map +1 -0
  47. package/dist/esm/reportCustomWebEvent/index.d.ts +6 -0
  48. package/dist/esm/reportCustomWebEvent/index.js +22 -0
  49. package/dist/esm/reportCustomWebEvent/index.js.map +1 -0
  50. package/dist/esm/reportWebEvent/generated-types.d.ts +25 -0
  51. package/dist/esm/reportWebEvent/generated-types.js +2 -0
  52. package/dist/esm/reportWebEvent/generated-types.js.map +1 -0
  53. package/dist/esm/reportWebEvent/index.d.ts +6 -0
  54. package/dist/esm/reportWebEvent/index.js +22 -0
  55. package/dist/esm/reportWebEvent/index.js.map +1 -0
  56. package/dist/esm/types.d.ts +26 -0
  57. package/dist/esm/types.js +2 -0
  58. package/dist/esm/types.js.map +1 -0
  59. package/dist/esm/utils.d.ts +6 -0
  60. package/dist/esm/utils.js +31 -0
  61. package/dist/esm/utils.js.map +1 -0
  62. package/dist/tsconfig.tsbuildinfo +1 -0
  63. package/package.json +24 -0
  64. package/src/__tests__/index.test.ts +300 -0
  65. package/src/fields.ts +484 -0
  66. package/src/generated-types.ts +12 -0
  67. package/src/index.ts +154 -0
  68. package/src/init-pixel.ts +31 -0
  69. package/src/reportCustomWebEvent/generated-types.ts +84 -0
  70. package/src/reportCustomWebEvent/index.ts +27 -0
  71. package/src/reportWebEvent/generated-types.ts +84 -0
  72. package/src/reportWebEvent/index.ts +27 -0
  73. package/src/types.ts +30 -0
  74. package/src/utils.ts +40 -0
  75. package/tsconfig.json +9 -0
@@ -0,0 +1,136 @@
1
+ import { browserDestination } from '@segment/browser-destination-runtime/shim';
2
+ import { defaultValues } from '@segment/actions-core';
3
+ import { initializePixel } from './init-pixel';
4
+ import reportWebEvent from './reportWebEvent';
5
+ import reportCustomWebEvent from './reportCustomWebEvent';
6
+ export const destination = {
7
+ name: 'Reddit Pixel',
8
+ slug: 'actions-reddit-pixel',
9
+ mode: 'device',
10
+ description: 'The Reddit Pixel Browser Destination allows you to install the Reddit Javascript pixel onto your site and pass mapped Segment events and metadata to Reddit.',
11
+ presets: [
12
+ {
13
+ name: 'Page Visit',
14
+ subscribe: 'type = "page"',
15
+ partnerAction: 'reportWebEvent',
16
+ mapping: {
17
+ ...defaultValues(reportWebEvent.fields),
18
+ tracking_type: 'PageVisit'
19
+ },
20
+ type: 'automatic'
21
+ },
22
+ {
23
+ name: 'View Content',
24
+ subscribe: 'type = "track" and event = "Product Viewed"',
25
+ partnerAction: 'reportWebEvent',
26
+ mapping: {
27
+ ...defaultValues(reportWebEvent.fields),
28
+ tracking_type: 'ViewContent'
29
+ },
30
+ type: 'automatic'
31
+ },
32
+ {
33
+ name: 'Search',
34
+ subscribe: 'type = "track" and event = "Products Searched"',
35
+ partnerAction: 'reportWebEvent',
36
+ mapping: {
37
+ ...defaultValues(reportWebEvent.fields),
38
+ tracking_type: 'Search'
39
+ },
40
+ type: 'automatic'
41
+ },
42
+ {
43
+ name: 'Add to Cart',
44
+ subscribe: 'type = "track" and event = "Product Added"',
45
+ partnerAction: 'reportWebEvent',
46
+ mapping: {
47
+ ...defaultValues(reportWebEvent.fields),
48
+ tracking_type: 'AddToCart',
49
+ event_metadata: {
50
+ currency: { '@path': '$.properties.currency' },
51
+ itemCount: { '@path': '$.properties.quantity' },
52
+ value: { '@path': '$.properties.price' }
53
+ }
54
+ },
55
+ type: 'automatic'
56
+ },
57
+ {
58
+ name: 'Add to Wishlist',
59
+ subscribe: 'type = "track" and event = "Product Added to Wishlist"',
60
+ partnerAction: 'reportWebEvent',
61
+ mapping: {
62
+ ...defaultValues(reportWebEvent.fields),
63
+ tracking_type: 'AddToWishlist',
64
+ event_metadata: {
65
+ currency: { '@path': '$.properties.currency' },
66
+ itemCount: { '@path': '$.properties.quantity' },
67
+ value: { '@path': '$.properties.price' }
68
+ }
69
+ },
70
+ type: 'automatic'
71
+ },
72
+ {
73
+ name: 'Purchase',
74
+ subscribe: 'type = "track" and event = "Order Completed"',
75
+ partnerAction: 'reportWebEvent',
76
+ mapping: {
77
+ ...defaultValues(reportWebEvent.fields),
78
+ tracking_type: 'Purchase'
79
+ },
80
+ type: 'automatic'
81
+ },
82
+ {
83
+ name: 'Lead',
84
+ subscribe: 'type = "track" and event = "Lead Generated"',
85
+ partnerAction: 'reportWebEvent',
86
+ mapping: {
87
+ ...defaultValues(reportWebEvent.fields),
88
+ tracking_type: 'Lead',
89
+ event_metadata: {
90
+ currency: { '@path': '$.properties.currency' },
91
+ value: { '@path': '$.properties.value' }
92
+ }
93
+ },
94
+ type: 'automatic'
95
+ },
96
+ {
97
+ name: 'Sign Up',
98
+ subscribe: 'type = "track" and event = "Signed Up"',
99
+ partnerAction: 'reportWebEvent',
100
+ mapping: {
101
+ ...defaultValues(reportWebEvent.fields),
102
+ tracking_type: 'SignUp',
103
+ event_metadata: {
104
+ currency: { '@path': '$.properties.currency' },
105
+ value: { '@path': '$.properties.value' }
106
+ }
107
+ },
108
+ type: 'automatic'
109
+ }
110
+ ],
111
+ settings: {
112
+ pixel_id: {
113
+ label: 'Pixel ID',
114
+ type: 'string',
115
+ description: 'Your Reddit Pixel ID',
116
+ required: true
117
+ },
118
+ ldu: {
119
+ label: 'Limited Data Use',
120
+ type: 'boolean',
121
+ default: false,
122
+ description: 'Limited Data Use - When the LDU flag is enabled, it may impact campaign performance and limit the size of targetable audiences. See [this documentation](https://business.reddithelp.com/s/article/Limited-Data-Use) for more information. If enabling this toggle, also go into each event and configure the Country and Region in the Data Processing Options for each event being sent.'
123
+ }
124
+ },
125
+ initialize: async ({ settings }, deps) => {
126
+ initializePixel(settings);
127
+ await deps.resolveWhen(() => window.rdt != null, 100);
128
+ return window.rdt;
129
+ },
130
+ actions: {
131
+ reportWebEvent,
132
+ reportCustomWebEvent
133
+ }
134
+ };
135
+ export default browserDestination(destination);
136
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2CAA2C,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AAQzD,MAAM,CAAC,MAAM,WAAW,GAAwD;IAC9E,IAAI,EAAE,cAAc;IACpB,IAAI,EAAE,sBAAsB;IAC5B,IAAI,EAAE,QAAQ;IACd,WAAW,EACT,8JAA8J;IAEhK,OAAO,EAAE;QACP;YACE,IAAI,EAAE,YAAY;YAClB,SAAS,EAAE,eAAe;YAC1B,aAAa,EAAE,gBAAgB;YAC/B,OAAO,EAAE;gBACP,GAAG,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC;gBACvC,aAAa,EAAE,WAAW;aAC3B;YACD,IAAI,EAAE,WAAW;SAClB;QACD;YACE,IAAI,EAAE,cAAc;YACpB,SAAS,EAAE,6CAA6C;YACxD,aAAa,EAAE,gBAAgB;YAC/B,OAAO,EAAE;gBACP,GAAG,aAAa,CAAC,cAAc,CAAC,MAAM,CAAC;gBACvC,aAAa,EAAE,aAAa;aAC7B;YACD,IAAI,EAAE,WAAW;SAClB;QACD;YACE,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,gDAAgD;YAC3D,aAAa,EAAE,gBAAgB;YAC/B,OAAO,EAAE;gBACP,GAAG,aAAa,C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1
+ export function initializePixel(settings) {
2
+ !(function (w, d) {
3
+ if (!w.rdt) {
4
+ var p = (w.rdt = function () {
5
+ p.sendEvent ? p.sendEvent.apply(p, arguments) : p.callQueue.push(arguments);
6
+ });
7
+ p.callQueue = [];
8
+ var t = d.createElement('script');
9
+ t.src = 'https://www.redditstatic.com/ads/pixel.js';
10
+ t.async = true;
11
+ var s = d.getElementsByTagName('script')[0];
12
+ s.parentNode.insertBefore(t, s);
13
+ }
14
+ })(window, document);
15
+ rdt.init = (pixel_id, ldu) => {
16
+ if (!rdt.init_already_called) {
17
+ rdt('init', pixel_id, ldu);
18
+ }
19
+ rdt.init_already_called = true;
20
+ };
21
+ rdt.track = (eventName, eventMetadata) => {
22
+ rdt('track', eventName, eventMetadata);
23
+ };
24
+ rdt.init_already_called = false;
25
+ }
26
+ //# sourceMappingURL=init-pixel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-pixel.js","sourceRoot":"","sources":["../../src/init-pixel.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,eAAe,CAAC,QAAQ;IACtC,CAAC,CAAC,UAAU,CAAC,EAAE,CAAC;QACd,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE;YACV,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG;gBACf,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YAC7E,CAAC,CAAC,CAAA;YACF,CAAC,CAAC,SAAS,GAAG,EAAE,CAAA;YAChB,IAAI,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;YACjC,CAAC,CAAC,GAAG,GAAG,2CAA2C,CAAA;YACnD,CAAC,CAAC,KAAK,GAAG,IAAI,CAAA;YACd,IAAI,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3C,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;SAChC;IACH,CAAC,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IAEpB,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,EAAE;QAC3B,IAAI,CAAC,GAAG,CAAC,mBAAmB,EAAE;YAC5B,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAA;SAC3B;QACD,GAAG,CAAC,mBAAmB,GAAG,IAAI,CAAA;IAChC,CAAC,CAAA;IAED,GAAG,CAAC,KAAK,GAAG,CAAC,SAAS,EAAE,aAAa,EAAE,EAAE;QACvC,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAA;IACxC,CAAC,CAAA;IAED,GAAG,CAAC,mBAAmB,GAAG,KAAK,CAAA;AACjC,CAAC"}
@@ -0,0 +1,25 @@
1
+ export interface Payload {
2
+ conversion_id?: string;
3
+ event_metadata?: {
4
+ currency?: string;
5
+ itemCount?: number;
6
+ value?: number;
7
+ };
8
+ user?: {
9
+ advertising_id?: string;
10
+ device_type?: string;
11
+ email?: string;
12
+ externalId?: string;
13
+ phoneNumber?: string;
14
+ };
15
+ products?: {
16
+ category?: string;
17
+ id?: string;
18
+ name?: string;
19
+ }[];
20
+ data_processing_options?: {
21
+ country?: string;
22
+ region?: string;
23
+ };
24
+ custom_event_name: string;
25
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/reportCustomWebEvent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ import { RedditPixel } from '../types';
5
+ declare const action: BrowserActionDefinition<Settings, RedditPixel, Payload>;
6
+ export default action;
@@ -0,0 +1,22 @@
1
+ import { conversion_id, event_metadata, user, products, data_processing_options, custom_event_name } from '../fields';
2
+ import { initPixel, trackCall } from '../utils';
3
+ const action = {
4
+ title: 'Reddit Pixel - Custom Event',
5
+ description: 'Send Custom Pixel Events to Reddit.',
6
+ defaultSubscription: 'type = "track"',
7
+ platform: 'web',
8
+ fields: {
9
+ conversion_id,
10
+ event_metadata,
11
+ user,
12
+ products,
13
+ data_processing_options,
14
+ custom_event_name
15
+ },
16
+ perform: (rdt, { payload, settings }) => {
17
+ initPixel(rdt, payload, settings);
18
+ trackCall(rdt, payload);
19
+ }
20
+ };
21
+ export default action;
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reportCustomWebEvent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAErH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,MAAM,GAA4D;IACtE,KAAK,EAAE,6BAA6B;IACpC,WAAW,EAAE,qCAAqC;IAClD,mBAAmB,EAAE,gBAAgB;IACrC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,aAAa;QACb,cAAc;QACd,IAAI;QACJ,QAAQ;QACR,uBAAuB;QACvB,iBAAiB;KAClB;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QACtC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QACjC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC;CACF,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,25 @@
1
+ export interface Payload {
2
+ tracking_type: string;
3
+ products?: {
4
+ category?: string;
5
+ id?: string;
6
+ name?: string;
7
+ }[];
8
+ user?: {
9
+ advertising_id?: string;
10
+ device_type?: string;
11
+ email?: string;
12
+ externalId?: string;
13
+ phoneNumber?: string;
14
+ };
15
+ data_processing_options?: {
16
+ country?: string;
17
+ region?: string;
18
+ };
19
+ event_metadata?: {
20
+ currency?: string;
21
+ itemCount?: number;
22
+ value?: number;
23
+ };
24
+ conversion_id?: string;
25
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=generated-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generated-types.js","sourceRoot":"","sources":["../../../src/reportWebEvent/generated-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types';
2
+ import type { Settings } from '../generated-types';
3
+ import type { Payload } from './generated-types';
4
+ import { RedditPixel } from '../types';
5
+ declare const action: BrowserActionDefinition<Settings, RedditPixel, Payload>;
6
+ export default action;
@@ -0,0 +1,22 @@
1
+ import { tracking_type, conversion_id, event_metadata, user, products, data_processing_options } from '../fields';
2
+ import { initPixel, trackCall } from '../utils';
3
+ const action = {
4
+ title: 'Reddit Pixel',
5
+ description: 'Send Standard Pixel Events to Reddit. This includes pagevisits, addtocarts, search, etc.',
6
+ defaultSubscription: 'type = "track"',
7
+ platform: 'web',
8
+ fields: {
9
+ tracking_type,
10
+ products,
11
+ user,
12
+ data_processing_options,
13
+ event_metadata,
14
+ conversion_id
15
+ },
16
+ perform: (rdt, { payload, settings }) => {
17
+ initPixel(rdt, payload, settings);
18
+ trackCall(rdt, payload);
19
+ }
20
+ };
21
+ export default action;
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reportWebEvent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AAEjH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAE/C,MAAM,MAAM,GAA4D;IACtE,KAAK,EAAE,cAAc;IACrB,WAAW,EAAE,0FAA0F;IACvG,mBAAmB,EAAE,gBAAgB;IACrC,QAAQ,EAAE,KAAK;IACf,MAAM,EAAE;QACN,aAAa;QACb,QAAQ;QACR,IAAI;QACJ,uBAAuB;QACvB,cAAc;QACd,aAAa;KACd;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE;QACtC,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QACjC,SAAS,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACzB,CAAC;CACF,CAAA;AAED,eAAe,MAAM,CAAA"}
@@ -0,0 +1,26 @@
1
+ export interface RedditPixel {
2
+ page: () => void;
3
+ init: (pixelId: string, ldu?: {
4
+ dpm?: string;
5
+ dpcc?: string;
6
+ dprc?: string;
7
+ }) => void;
8
+ track: (eventName: string, eventMetadata?: EventMetadata) => void;
9
+ }
10
+ export interface EventMetadata {
11
+ currency?: string;
12
+ itemCount?: number;
13
+ value?: number;
14
+ customEventName?: string;
15
+ conversionId?: string;
16
+ aaid?: string;
17
+ idfa?: string;
18
+ email?: string;
19
+ phoneNumber?: string;
20
+ externalId?: string;
21
+ products?: {
22
+ id?: string | undefined;
23
+ category?: string | undefined;
24
+ name?: string | undefined;
25
+ }[];
26
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { Settings } from './generated-types';
2
+ import type { Payload as StandardEvent } from './reportWebEvent/generated-types';
3
+ import type { Payload as CustomEvent } from './reportCustomWebEvent/generated-types';
4
+ import { RedditPixel } from './types';
5
+ export declare function initPixel(rdt: RedditPixel, payload: StandardEvent | CustomEvent, settings: Settings): void;
6
+ export declare function trackCall(rdt: RedditPixel, payload: StandardEvent | CustomEvent): void;
@@ -0,0 +1,31 @@
1
+ export function initPixel(rdt, payload, settings) {
2
+ rdt.init(settings.pixel_id, {
3
+ ...(settings.ldu && {
4
+ dpm: 'LDU',
5
+ dpcc: payload.data_processing_options?.country,
6
+ dprc: payload.data_processing_options?.region
7
+ })
8
+ });
9
+ }
10
+ export function trackCall(rdt, payload) {
11
+ if (['PageVisit', 'ViewContent', 'Search'].includes(payload?.tracking_type)) {
12
+ delete payload.event_metadata;
13
+ }
14
+ const fullPayload = {
15
+ ...payload.event_metadata,
16
+ products: payload.products ?? undefined,
17
+ conversionId: payload.conversion_id ?? undefined,
18
+ email: payload?.user?.email ?? undefined,
19
+ externalId: payload?.user?.externalId ?? undefined,
20
+ phoneNumber: payload?.user?.phoneNumber ?? undefined,
21
+ aaid: payload?.user?.advertising_id && payload?.user?.device_type?.toLowerCase() === 'android'
22
+ ? payload?.user?.advertising_id
23
+ : undefined,
24
+ idfa: payload?.user?.advertising_id && payload?.user?.device_type?.toLowerCase() === 'ios'
25
+ ? payload?.user?.advertising_id
26
+ : undefined,
27
+ customEventName: payload.custom_event_name ?? undefined
28
+ };
29
+ rdt.track(payload.tracking_type ?? 'Custom', fullPayload);
30
+ }
31
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,SAAS,CAAC,GAAgB,EAAE,OAAoC,EAAE,QAAkB;IAClG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;QAC1B,GAAG,CAAC,QAAQ,CAAC,GAAG,IAAI;YAClB,GAAG,EAAE,K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