Skip to content

Commit 1da3d5e

Browse files
KSD-31: Improve email comparisons for profile deduplication (#250)
1 parent 77553f4 commit 1da3d5e

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

plugin/src/infrastructure/driven/klaviyo/KlaviyoSdkService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ export class KlaviyoSdkService extends KlaviyoService {
114114
// If multiple profiles exist with same email, return the first one
115115
// In practice, Klaviyo should prevent duplicates, but we handle edge case
116116
const profile = profiles?.body.data?.find(
117-
(profile: GetProfileResponseData) => profile.attributes.email === email,
117+
(profile: GetProfileResponseData) =>
118+
profile.attributes.email?.toLowerCase() === email.toLowerCase(),
118119
);
119120
if (profiles?.body.data && profiles.body.data.length > 1) {
120121
logger.warn('Multiple profiles found for email. Using first match.');

plugin/src/test/e2e/postman/klaviyo-e2e-tests.postman_collection.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
" pm.test(\"Profile was created in klaviyo\", function () {",
367367
" pm.response.to.have.status(expectedHttpStatus);",
368368
" pm.expect(jsonData.data.length).to.be.above(0);",
369-
" pm.expect(jsonData.data[0].attributes.email).to.eql(pm.environment.get(\"customer-email\"));",
369+
" pm.expect(jsonData.data[0].attributes.email.toLowerCase()).to.eql(pm.environment.get(\"customer-email\").toLowerCase());",
370370
" });",
371371
"}",
372372
""
@@ -1984,7 +1984,7 @@
19841984
" pm.expect(jsonData.data.length).to.be.above(0);",
19851985
" });",
19861986
"",
1987-
" const profile = jsonData.data.find(p => p.attributes.email === pm.environment.get(\"dedup-customer-email\"));",
1987+
" const profile = jsonData.data.find(p => p.attributes.email.toLowerCase() === pm.environment.get(\"dedup-customer-email\").toLowerCase());",
19881988
" if (profile && profile.id) {",
19891989
" pm.environment.set(\"existing-klaviyo-profile-id\", profile.id);",
19901990
" console.log(\"Found existing profile with ID: \" + profile.id);",
@@ -2287,7 +2287,7 @@
22872287
"}",
22882288
"",
22892289
"const jsonData = pm.response.json();",
2290-
"const profile = jsonData.data ? jsonData.data.find(p => p.attributes.email === pm.environment.get(\"dedup-customer-email\")) : null;",
2290+
"const profile = jsonData.data ? jsonData.data.find(p => p.attributes.email.toLowerCase() === pm.environment.get(\"dedup-customer-email\").toLowerCase()) : null;",
22912291
"const profileFound = profile !== null && profile !== undefined;",
22922292
"const externalIdSet = profile && profile.attributes && profile.attributes.external_id === pm.environment.get(\"customer-id\");",
22932293
"const elapsedTime = Date.now() - parseInt(startTime, 10);",

0 commit comments

Comments
 (0)