Skip to content

Commit 09ee94c

Browse files
author
Diego dos Santos
committed
feat: add URL truncation on trackQuizResultsLoaded method
1 parent 8200eed commit 09ee94c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

spec/src/modules/tracker.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7460,6 +7460,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
74607460

74617461
expect(tracker.trackQuizResultsLoaded(requiredParameters)).to.equal(true);
74627462
});
7463+
7464+
it('Should truncate url param to 2048 characters max', (done) => {
7465+
const longUrl = createLongUrl(3000);
7466+
const truncatedUrl = longUrl.slice(0, 2048);
7467+
7468+
const { tracker } = new ConstructorIO({
7469+
apiKey: testApiKey,
7470+
fetch: fetchSpy,
7471+
...requestQueueOptions,
7472+
});
7473+
7474+
tracker.on('success', () => {
7475+
const requestParams = helpers.extractBodyParamsFromFetch(fetchSpy);
7476+
7477+
// Request
7478+
expect(fetchSpy).to.have.been.called;
7479+
expect(requestParams.url).to.equal(truncatedUrl);
7480+
7481+
done();
7482+
});
7483+
7484+
const parameters = {
7485+
...requiredParameters,
7486+
url: longUrl,
7487+
};
7488+
7489+
expect(tracker.trackQuizResultsLoaded(parameters)).to.equal(true);
7490+
});
74637491
});
74647492

74657493
describe('trackQuizResultClick', () => {

src/modules/tracker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2022,7 +2022,7 @@ class Tracker {
20222022
bodyParams.quiz_id = quizId;
20232023
bodyParams.quiz_version_id = quizVersionId;
20242024
bodyParams.quiz_session_id = quizSessionId;
2025-
bodyParams.url = url;
2025+
bodyParams.url = helpers.truncateString(url, MAX_URL_LENGTH);
20262026

20272027
if (!helpers.isNil(section)) {
20282028
if (typeof section !== 'string') {

0 commit comments

Comments
 (0)