1
- import type { Features , RequestClient } from '@segment/actions-core'
1
+ import type { RequestClient } from '@segment/actions-core'
2
2
import type { Settings } from './generated-types'
3
3
import type { Payload as StandardEvent } from './standardEvent/generated-types'
4
4
import type { Payload as CustomEvent } from './customEvent/generated-types'
@@ -10,7 +10,7 @@ import {
10
10
EventMetadata ,
11
11
DatapProcessingOptions
12
12
} from './types'
13
- import { processHashing } from '../../lib/hashing-utils'
13
+ import { processHashingV2 } from '../../lib/hashing-utils'
14
14
15
15
type EventMetadataType = StandardEvent [ 'event_metadata' ] | CustomEvent [ 'event_metadata' ]
16
16
type ProductsType = StandardEvent [ 'products' ] | CustomEvent [ 'products' ]
@@ -19,25 +19,16 @@ type DataProcessingOptionsType = StandardEvent['data_processing_options'] | Cust
19
19
type UserType = StandardEvent [ 'user' ] | CustomEvent [ 'user' ]
20
20
type ScreenDimensionsType = StandardEvent [ 'screen_dimensions' ] | CustomEvent [ 'screen_dimensions' ]
21
21
22
- export async function send (
23
- request : RequestClient ,
24
- settings : Settings ,
25
- payload : StandardEvent [ ] | CustomEvent [ ] ,
26
- features ?: Features
27
- ) {
28
- const data = createRedditPayload ( payload , settings , features )
22
+ export async function send ( request : RequestClient , settings : Settings , payload : StandardEvent [ ] | CustomEvent [ ] ) {
23
+ const data = createRedditPayload ( payload , settings )
29
24
return request ( `https://ads-api.reddit.com/api/v2.0/conversions/events/${ settings . ad_account_id } ` , {
30
25
method : 'POST' ,
31
26
headers : { Authorization : `Bearer ${ settings . conversion_token } ` } ,
32
27
json : JSON . parse ( JSON . stringify ( data ) )
33
28
} )
34
29
}
35
30
36
- function createRedditPayload (
37
- payloads : StandardEvent [ ] | CustomEvent [ ] ,
38
- settings : Settings ,
39
- features ?: Features
40
- ) : StandardEventPayload {
31
+ function createRedditPayload ( payloads : StandardEvent [ ] | CustomEvent [ ] , settings : Settings ) : StandardEventPayload {
41
32
const payloadItems : StandardEventPayloadItem [ ] = [ ]
42
33
43
34
payloads . forEach ( ( payload ) => {
@@ -64,8 +55,8 @@ function createRedditPayload(
64
55
custom_event_name : clean ( custom_event_name )
65
56
} ,
66
57
click_id : clean ( click_id ) ,
67
- event_metadata : getMetadata ( event_metadata , products , conversion_id , features ) ,
68
- user : getUser ( user , data_processing_options , screen_dimensions , features )
58
+ event_metadata : getMetadata ( event_metadata , products , conversion_id ) ,
59
+ user : getUser ( user , data_processing_options , screen_dimensions )
69
60
}
70
61
71
62
payloadItems . push ( payloadItem )
@@ -105,8 +96,7 @@ function getProducts(products: ProductsType): Product[] | undefined {
105
96
function getMetadata (
106
97
metadata : EventMetadataType ,
107
98
products : ProductsType ,
108
- conversion_id : ConversionIdType ,
109
- features ?: Features
99
+ conversion_id : ConversionIdType
110
100
) : EventMetadata | undefined {
111
101
if ( ! metadata && ! products && ! conversion_id ) {
112
102
return undefined
@@ -117,18 +107,14 @@ function getMetadata(
117
107
item_count : cleanNum ( metadata ?. item_count ) ,
118
108
value_decimal : cleanNum ( metadata ?. value_decimal ) ,
119
109
products : getProducts ( products ) ,
120
- conversion_id : smartHash ( conversion_id , features , ( value ) => value . trim ( ) )
110
+ conversion_id : smartHash ( conversion_id , ( value ) => value . trim ( ) )
121
111
}
122
112
}
123
113
124
- function getAdId (
125
- device_type ?: string ,
126
- advertising_id ?: string ,
127
- features ?: Features
128
- ) : { [ key : string ] : string | undefined } | undefined {
114
+ function getAdId ( device_type ?: string , advertising_id ?: string ) : { [ key : string ] : string | undefined } | undefined {
129
115
if ( ! device_type ) return undefined
130
116
if ( ! advertising_id ) return undefined
131
- const hashedAdId = smartHash ( advertising_id , features )
117
+ const hashedAdId = smartHash ( advertising_id )
132
118
return device_type === 'ios' ? { idfa : hashedAdId } : { aaid : hashedAdId }
133
119
}
134
120
@@ -154,16 +140,15 @@ function getScreen(height?: number, width?: number): { height: number; width: nu
154
140
function getUser (
155
141
user : UserType ,
156
142
dataProcessingOptions : DataProcessingOptionsType ,
157
- screenDimensions : ScreenDimensionsType ,
158
- features ?: Features
143
+ screenDimensions : ScreenDimensionsType
159
144
) : User | undefined {
160
145
if ( ! user ) return
161
146
162
147
return {
163
- ...getAdId ( user . device_type , user . advertising_id , features ) ,
164
- email : smartHash ( user . email , features , canonicalizeEmail ) ,
165
- external_id : smartHash ( user . external_id , features , ( value ) => value . trim ( ) ) ,
166
- ip_address : smartHash ( user . ip_address , features , ( value ) => value . trim ( ) ) ,
148
+ ...getAdId ( user . device_type , user . advertising_id ) ,
149
+ email : smartHash ( user . email , canonicalizeEmail ) ,
150
+ external_id : smartHash ( user . external_id , ( value ) => value . trim ( ) ) ,
151
+ ip_address : smartHash ( user . ip_address , ( value ) => value . trim ( ) ) ,
167
152
user_agent : clean ( user . user_agent ) ,
168
153
uuid : clean ( user . uuid ) ,
169
154
data_processing_options : getDataProcessingOptions ( dataProcessingOptions ) ,
@@ -178,11 +163,7 @@ function canonicalizeEmail(value: string): string {
178
163
return `${ localPart . toLowerCase ( ) } @${ localPartAndDomain [ 1 ] . toLowerCase ( ) } `
179
164
}
180
165
181
- const smartHash = (
182
- value : string | undefined ,
183
- features ?: Features ,
184
- cleaningFunction ?: ( value : string ) => string
185
- ) : string | undefined => {
166
+ const smartHash = ( value : string | undefined , cleaningFunction ?: ( value : string ) => string ) : string | undefined => {
186
167
if ( value === undefined ) return
187
- return processHashing ( value , 'sha256' , 'hex' , features , 'actions-reddit-conversions-api ', cleaningFunction )
168
+ return processHashingV2 ( value , 'sha256' , 'hex' , cleaningFunction )
188
169
}
0 commit comments