Skip to content

Commit d1e86d4

Browse files
authored
fix: Remove case sesitivity from query params for integration captures (#1031)
1 parent c9e1cf4 commit d1e86d4

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

src/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ const queryStringParser = (
274274
): Dictionary<string> => {
275275
let urlParams: URLSearchParams | URLSearchParamsFallback;
276276
let results: Dictionary<string> = {};
277+
let lowerCaseUrlParams: Dictionary<string> = {};
277278

278279
if (!url) return results;
279280

@@ -284,13 +285,15 @@ const queryStringParser = (
284285
urlParams = queryStringParserFallback(url);
285286
}
286287

288+
urlParams.forEach((value, key) => {
289+
lowerCaseUrlParams[key.toLowerCase()] = value;
290+
});
291+
287292
if (isEmpty(keys)) {
288-
urlParams.forEach((value, key) => {
289-
results[key] = value;
290-
});
293+
return lowerCaseUrlParams;
291294
} else {
292295
keys.forEach(key => {
293-
const value = urlParams.get(key);
296+
const value = lowerCaseUrlParams[key.toLowerCase()];
294297
if (value) {
295298
results[key] = value;
296299
}

test/jest/integration-capture.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ describe('Integration Capture', () => {
145145
ScCid: '1234',
146146
});
147147
});
148+
149+
it('should capture Snapchat specific click ids without being case sensitive', () => {
150+
const url = new URL('https://www.example.com/?sccid=1234');
151+
152+
window.location.href = url.href;
153+
window.location.search = url.search;
154+
155+
const integrationCapture = new IntegrationCapture();
156+
integrationCapture.capture();
157+
158+
expect(integrationCapture.clickIds).toEqual({
159+
ScCid: '1234',
160+
});
161+
});
148162
});
149163

150164
describe('Facebook Click Ids', () => {

test/jest/utils.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,23 @@ describe('Utils', () => {
173173

174174
expect(queryStringParser(malformedUrl, keys)).toEqual(expectedResult);
175175
});
176+
177+
it('should handle different params case sensitivity and return them as lowercased params', () => {
178+
const url = 'https://www.example.com?FoO=bar&bAz=qux&NARF=poit'
179+
const keys = [
180+
'foo',
181+
'baz',
182+
'narf',
183+
];
184+
185+
const expectedResult = {
186+
foo: 'bar',
187+
narf: 'poit',
188+
baz: 'qux',
189+
};
190+
191+
expect(queryStringParser(url, keys)).toEqual(expectedResult);
192+
});
176193
});
177194
});
178195

0 commit comments

Comments
 (0)