@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,84 @@
1
+ // Generated file. DO NOT MODIFY IT BY HAND.
2
+
3
+ export interface Payload {
4
+ /**
5
+ * The unique conversion ID that corresponds to a distinct conversion event. This is used for deduplication. If you are using both Reddit Pixel and CAPI integrations, this field is required in order to dedupe the same events across both sources.
6
+ */
7
+ conversion_id?: string
8
+ /**
9
+ * The metadata associated with the conversion event.
10
+ */
11
+ event_metadata?: {
12
+ /**
13
+ * The currency for the value provided. This must be a three-character ISO 4217 currency code. This should only be set for revenue-related events.
14
+ */
15
+ currency?: string
16
+ /**
17
+ * The number of items in the event. This should only be set for revenue-related events.
18
+ */
19
+ itemCount?: number
20
+ /**
21
+ * The value of the transaction in the base unit of the currency. This should only be set for revenue-related events.
22
+ */
23
+ value?: number
24
+ }
25
+ /**
26
+ * The identifying user parameters associated with the conversion event.
27
+ */
28
+ user?: {
29
+ /**
30
+ * The mobile advertising ID for the user. This can be the iOS IDFA, Android AAID.
31
+ */
32
+ advertising_id?: string
33
+ /**
34
+ * The type of mobile device. e.g. iOS or Android.
35
+ */
36
+ device_type?: string
37
+ /**
38
+ * The email address of the user.
39
+ */
40
+ email?: string
41
+ /**
42
+ * An advertiser-assigned persistent identifier for the user.
43
+ */
44
+ externalId?: string
45
+ /**
46
+ * The phone number of the user in E.164 standard format.
47
+ */
48
+ phoneNumber?: string
49
+ }
50
+ /**
51
+ * The products associated with the conversion event.
52
+ */
53
+ products?: {
54
+ /**
55
+ * The category the product.
56
+ */
57
+ category?: string
58
+ /**
59
+ * The ID representing the product in a catalog
60
+ */
61
+ id?: string
62
+ /**
63
+ * The name of the product
64
+ */
65
+ name?: string
66
+ }[]
67
+ /**
68
+ * A structure of data processing options to specify the processing type for the event. This is only used for LDU - when the LDU flag is enabled, it may impact campaign performance and limit the size of targetable audiences.
69
+ */
70
+ data_processing_options?: {
71
+ /**
72
+ * Country Code of the user. We support ISO 3166-1 alpha-2 country code.
73
+ */
74
+ country?: string
75
+ /**
76
+ * Region Code of the user. We support ISO 3166-2 region code, ex: "US-CA, US-NY, etc." or just the region code without country prefix, e.g. "CA, NY, etc.". This is only used for LDU - when the LDU flag is enabled, it may impact campaign performance and limit the size of targetable audiences.
77
+ */
78
+ region?: string
79
+ }
80
+ /**
81
+ * A custom event name that can be passed when tracking_type is set to "Custom". All UTF-8 characters are accepted and custom_event_name must be at most 64 characters long.
82
+ */
83
+ custom_event_name: string
84
+ }
@@ -0,0 +1,27 @@
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 { conversion_id, event_metadata, user, products, data_processing_options, custom_event_name } from '../fields'
5
+ import { RedditPixel } from '../types'
6
+ import { initPixel, trackCall } from '../utils'
7
+
8
+ const action: BrowserActionDefinition<Settings, RedditPixel, Payload> = {
9
+ title: 'Reddit Pixel - Custom Event',
10
+ description: 'Send Custom Pixel Events to Reddit.',
11
+ defaultSubscription: 'type = "track"',
12
+ platform: 'web',
13
+ fields: {
14
+ conversion_id,
15
+ event_metadata,
16
+ user,
17
+ products,
18
+ data_processing_options,
19
+ custom_event_name
20
+ },
21
+ perform: (rdt, { payload, settings }) => {
22
+ initPixel(rdt, payload, settings)
23
+ trackCall(rdt, payload)
24
+ }
25
+ }
26
+
27
+ export default action
@@ -0,0 +1,84 @@
1
+ // Generated file. DO NOT MODIFY IT BY HAND.
2
+
3
+ export interface Payload {
4
+ /**
5
+ * One of Reddit Pixel's standard conversion event types. To send a Custom event to Reddit use the Custom Event Action instead.
6
+ */
7
+ tracking_type: string
8
+ /**
9
+ * The products associated with the conversion event.
10
+ */
11
+ products?: {
12
+ /**
13
+ * The category the product.
14
+ */
15
+ category?: string
16
+ /**
17
+ * The ID representing the product in a catalog
18
+ */
19
+ id?: string
20
+ /**
21
+ * The name of the product
22
+ */
23
+ name?: string
24
+ }[]
25
+ /**
26
+ * The identifying user parameters associated with the conversion event.
27
+ */
28
+ user?: {
29
+ /**
30
+ * The mobile advertising ID for the user. This can be the iOS IDFA, Android AAID.
31
+ */
32
+ advertising_id?: string
33
+ /**
34
+ * The type of mobile device. e.g. iOS or Android.
35
+ */
36
+ device_type?: string
37
+ /**
38
+ * The email address of the user.
39
+ */
40
+ email?: string
41
+ /**
42
+ * An advertiser-assigned persistent identifier for the user.
43
+ */
44
+ externalId?: string
45
+ /**
46
+ * The phone number of the user in E.164 standard format.
47
+ */
48
+ phoneNumber?: string
49
+ }
50
+ /**
51
+ * A structure of data processing options to specify the processing type for the event. This is only used for LDU - when the LDU flag is enabled, it may impact campaign performance and limit the size of targetable audiences.
52
+ */
53
+ data_processing_options?: {
54
+ /**
55
+ * Country Code of the user. We support ISO 3166-1 alpha-2 country code.
56
+ */
57
+ country?: string
58
+ /**
59
+ * Region Code of the user. We support ISO 3166-2 region code, ex: "US-CA, US-NY, etc." or just the region code without country prefix, e.g. "CA, NY, etc.". This is only used for LDU - when the LDU flag is enabled, it may impact campaign performance and limit the size of targetable audiences.
60
+ */
61
+ region?: string
62
+ }
63
+ /**
64
+ * The metadata associated with the conversion event.
65
+ */
66
+ event_metadata?: {
67
+ /**
68
+ * The currency for the value provided. This must be a three-character ISO 4217 currency code. This should only be set for revenue-related events.
69
+ */
70
+ currency?: string
71
+ /**
72
+ * The number of items in the event. This should only be set for revenue-related events.
73
+ */
74
+ itemCount?: number
75
+ /**
76
+ * The value of the transaction in the base unit of the currency. This should only be set for revenue-related events.
77
+ */
78
+ value?: number
79
+ }
80
+ /**
81
+ * The unique conversion ID that corresponds to a distinct conversion event. This is used for deduplication. If you are using both Reddit Pixel and CAPI integrations, this field is required in order to dedupe the same events across both sources.
82
+ */
83
+ conversion_id?: string
84
+ }
@@ -0,0 +1,27 @@
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 { tracking_type, conversion_id, event_metadata, user, products, data_processing_options } from '../fields'
5
+ import { RedditPixel } from '../types'
6
+ import { initPixel, trackCall } from '../utils'
7
+
8
+ const action: BrowserActionDefinition<Settings, RedditPixel, Payload> = {
9
+ title: 'Reddit Pixel',
10
+ description: 'Send Standard Pixel Events to Reddit. This includes pagevisits, addtocarts, search, etc.',
11
+ defaultSubscription: 'type = "track"',
12
+ platform: 'web',
13
+ fields: {
14
+ tracking_type,
15
+ products,
16
+ user,
17
+ data_processing_options,
18
+ event_metadata,
19
+ conversion_id
20
+ },
21
+ perform: (rdt, { payload, settings }) => {
22
+ initPixel(rdt, payload, settings)
23
+ trackCall(rdt, payload)
24
+ }
25
+ }
26
+
27
+ export default action
package/src/types.ts ADDED
@@ -0,0 +1,30 @@
1
+ export interface RedditPixel {
2
+ page: () => void
3
+ init: (
4
+ pixelId: string,
5
+ ldu?: {
6
+ dpm?: string
7
+ dpcc?: string
8
+ dprc?: string
9
+ }
10
+ ) => void
11
+ track: (eventName: string, eventMetadata?: EventMetadata) => void
12
+ }
13
+
14
+ export interface EventMetadata {
15
+ currency?: string
16
+ itemCount?: number
17
+ value?: number
18
+ customEventName?: string
19
+ conversionId?: string
20
+ aaid?: string
21
+ idfa?: string
22
+ email?: string
23
+ phoneNumber?: string
24
+ externalId?: string
25
+ products?: {
26
+ id?: string | undefined
27
+ category?: string | undefined
28
+ name?: string | undefined
29
+ }[]
30
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,40 @@
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, EventMetadata } from './types'
5
+
6
+ export function initPixel(rdt: RedditPixel, payload: StandardEvent | CustomEvent, settings: Settings) {
7
+ rdt.init(settings.pixel_id, {
8
+ ...(settings.ldu && {
9
+ dpm: 'LDU', // Currently "LDU" is the only value supported if the LDU toggle is enabled.
10
+ dpcc: payload.data_processing_options?.country,
11
+ dprc: payload.data_processing_options?.region
12
+ })
13
+ })
14
+ }
15
+
16
+ export function trackCall(rdt: RedditPixel, payload: StandardEvent | CustomEvent) {
17
+ if (['PageVisit', 'ViewContent', 'Search'].includes((payload as StandardEvent)?.tracking_type)) {
18
+ delete payload.event_metadata
19
+ }
20
+
21
+ const fullPayload: EventMetadata = {
22
+ ...payload.event_metadata,
23
+ products: payload.products ?? undefined,
24
+ conversionId: payload.conversion_id ?? undefined,
25
+ email: payload?.user?.email ?? undefined,
26
+ externalId: payload?.user?.externalId ?? undefined,
27
+ phoneNumber: payload?.user?.phoneNumber ?? undefined,
28
+ aaid:
29
+ payload?.user?.advertising_id && payload?.user?.device_type?.toLowerCase() === 'android'
30
+ ? payload?.user?.advertising_id
31
+ : undefined,
32
+ idfa:
33
+ payload?.user?.advertising_id && payload?.user?.device_type?.toLowerCase() === 'ios'
34
+ ? payload?.user?.advertising_id
35
+ : undefined,
36
+ customEventName: (payload as CustomEvent).custom_event_name ?? undefined
37
+ }
38
+
39
+ rdt.track((payload as StandardEvent).tracking_type ?? 'Custom', fullPayload)
40
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "baseUrl": "."
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["dist", "**/__tests__"]
9
+ }