Skip to content

Commit

Permalink
Reddit-CAPI: hashing conversion_id & separating hashEmail function (#…
Browse files Browse the repository at this point in the history
…2468)

* hashing conv id + hashEmail func

* fixing tests

* fixing tests

---------

Co-authored-by: Manik Mehta <[email protected]>
Co-authored-by: Joe Ayoub <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent e4f699d commit db89a1d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"click_id": "Q1Q49h4LP@",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "Q1Q49h4LP@",
"conversion_id": "4fbe858b31ee34144cc3d009fd4636ef20fb342e095570d49a9898bb8d77598e",
"currency": "EUR",
"item_count": -2840640572358656,
"products": Array [
Expand Down Expand Up @@ -56,7 +56,7 @@ Object {
"click_id": "Q1Q49h4LP@",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "Q1Q49h4LP@",
"conversion_id": "4fbe858b31ee34144cc3d009fd4636ef20fb342e095570d49a9898bb8d77598e",
},
"event_type": Object {
"custom_event_name": "Q1Q49h4LP@",
Expand All @@ -76,7 +76,7 @@ Object {
"click_id": "gT6gXh8ga!%xhI",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "gT6gXh8ga!%xhI",
"conversion_id": "f136d03523cc17ecdfe2a4df68a819e5e98f6981316b7e50e1a8b34b018c70ae",
"currency": "GBP",
"item_count": 2091000289820672,
"products": Array [
Expand Down Expand Up @@ -124,7 +124,7 @@ Object {
"click_id": "gT6gXh8ga!%xhI",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "gT6gXh8ga!%xhI",
"conversion_id": "f136d03523cc17ecdfe2a4df68a819e5e98f6981316b7e50e1a8b34b018c70ae",
},
"event_type": Object {
"tracking_type": "AddToWishlist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Reddit Conversions Api', () => {
userId: 'user_id_1',
properties: {
click_id: 'click_id_1',
conversion_id: 'conversion_id_1',
conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375',
currency: 'USD',
quantity: 10,
total: 100,
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('Reddit Conversions Api', () => {
click_id: 'click_id_1',
event_at: '2024-01-08T13:52:50.212Z',
event_metadata: {
conversion_id: 'conversion_id_1',
conversion_id: '492ebaa71872336ef94c7093b77d2232fdba7e469f716586a816d861367b183f',
currency: 'USD',
item_count: 10,
products: [
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Reddit Conversions Api', () => {
userId: 'user_id_1',
properties: {
click_id: 'click_id_1',
conversion_id: 'conversion_id_1',
conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375',
currency: 'USD',
quantity: 10,
total: 100,
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('Reddit Conversions Api', () => {
click_id: 'click_id_1',
event_at: '2024-01-08T13:52:50.212Z',
event_metadata: {
conversion_id: 'conversion_id_1',
conversion_id: '492ebaa71872336ef94c7093b77d2232fdba7e469f716586a816d861367b183f',
currency: 'USD',
item_count: 10,
products: [
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('Reddit Conversions Api', () => {
userId: 'user_id_1',
properties: {
click_id: 'click_id_1',
conversion_id: 'conversion_id_1',
conversion_id: 'ea3d01f99e303d2338cfb4e71f182441eb57c9a3cb129c40bcae9f5d641a7375',
currency: 'USD',
total: 100,
uuid: 'uuid_1',
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('Reddit Conversions Api', () => {
click_id: 'click_id_1',
event_at: '2024-01-08T13:52:50.212Z',
event_metadata: {
conversion_id: 'conversion_id_1',
conversion_id: '492ebaa71872336ef94c7093b77d2232fdba7e469f716586a816d861367b183f',
currency: 'USD',
products: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"click_id": "1dc[GGJK6O%*76J4O6Mz",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "1dc[GGJK6O%*76J4O6Mz",
"conversion_id": "7b1d43d3d43059efd3e755045cf79aa9a554bc456f4c10d1915ccb5d79345b4a",
"currency": "USD",
"item_count": 8361377294974976,
"products": Array [
Expand Down Expand Up @@ -56,7 +56,7 @@ Object {
"click_id": "1dc[GGJK6O%*76J4O6Mz",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "1dc[GGJK6O%*76J4O6Mz",
"conversion_id": "7b1d43d3d43059efd3e755045cf79aa9a554bc456f4c10d1915ccb5d79345b4a",
},
"event_type": Object {
"custom_event_name": "1dc[GGJK6O%*76J4O6Mz",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object {
"click_id": "a@UzPN)1pp@tLb)vQZ2s",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "a@UzPN)1pp@tLb)vQZ2s",
"conversion_id": "7da4d4522d67f6ca1c1b0654c2d91c916a22667a5d34fa75c7cdcbe0c1b452ce",
"currency": "USD",
"item_count": 8501184792887296,
"products": Array [
Expand Down Expand Up @@ -55,7 +55,7 @@ Object {
"click_id": "a@UzPN)1pp@tLb)vQZ2s",
"event_at": "2021-02-01T00:00:00.000Z",
"event_metadata": Object {
"conversion_id": "a@UzPN)1pp@tLb)vQZ2s",
"conversion_id": "7da4d4522d67f6ca1c1b0654c2d91c916a22667a5d34fa75c7cdcbe0c1b452ce",
},
"event_type": Object {
"tracking_type": "SignUp",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function getMetadata(
item_count: cleanNum(metadata?.item_count),
value_decimal: cleanNum(metadata?.value_decimal),
products: getProducts(products),
conversion_id: clean(conversion_id)
conversion_id: hash(clean(conversion_id))
}
}

Expand Down Expand Up @@ -145,7 +145,7 @@ function getUser(

return {
...getAdId(user.device_type, user.advertising_id),
email: hash(clean(user.email), true),
email: hashEmail(clean(user.email)),
external_id: hash(clean(user.external_id)),
ip_address: hash(clean(user.ip_address)),
user_agent: clean(user.user_agent),
Expand All @@ -161,12 +161,16 @@ function canonicalizeEmail(value: string): string {
return `${localPart.toLowerCase()}@${localPartAndDomain[1].toLowerCase()}`
}

const hash = (value: string | undefined, isEmail = false): string | undefined => {
function hashEmail(email: string | undefined): string | undefined {
if (email === undefined) return
const canonicalEmail = canonicalizeEmail(email)
return hash(canonicalEmail)
}

const hash = (value: string | undefined): string | undefined => {
if (value === undefined) return
if (isEmail) {
value = canonicalizeEmail(value)
}
const hash = createHash('sha256')
hash.update(value)
return hash.digest('hex')
}

0 comments on commit db89a1d

Please sign in to comment.