@@ -34,6 +34,11 @@ function validateOriginReferrer(requestParams) {
3434 expect ( requestParams ) . to . have . property ( 'origin_referrer' ) . to . contain ( 'utm_campaign=campaign_1' ) ;
3535}
3636
37+ function createLongUrl ( length ) {
38+ const baseUrl = 'https://constructor.io/product/KMH876?a=' ;
39+ return `${ baseUrl } ${ 'a' . repeat ( length - baseUrl . length ) } ` ;
40+ }
41+
3742describe ( `ConstructorIO - Tracker${ bundledDescriptionSuffix } ` , ( ) => {
3843 let fetchSpy = null ;
3944 let cleanup ;
@@ -1465,6 +1470,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
14651470 expect ( tracker . trackItemDetailLoad ( requiredParameters ) ) . to . equal ( true ) ;
14661471 } ) ;
14671472 }
1473+
1474+ it ( 'Should truncate url param to 2048 characters max' , ( done ) => {
1475+ const longUrl = createLongUrl ( 3000 ) ;
1476+ const truncatedUrl = longUrl . slice ( 0 , 2048 ) ;
1477+
1478+ const { tracker } = new ConstructorIO ( {
1479+ apiKey : testApiKey ,
1480+ fetch : fetchSpy ,
1481+ ...requestQueueOptions ,
1482+ } ) ;
1483+
1484+ tracker . on ( 'success' , ( ) => {
1485+ const requestParams = helpers . extractBodyParamsFromFetch ( fetchSpy ) ;
1486+
1487+ // Request
1488+ expect ( fetchSpy ) . to . have . been . called ;
1489+ expect ( requestParams . url ) . to . equal ( truncatedUrl ) ;
1490+
1491+ done ( ) ;
1492+ } ) ;
1493+
1494+ const parameters = {
1495+ ...requiredParameters ,
1496+ url : longUrl ,
1497+ } ;
1498+
1499+ expect ( tracker . trackItemDetailLoad ( parameters ) ) . to . equal ( true ) ;
1500+ } ) ;
14681501 } ) ;
14691502
14701503 describe ( 'trackSearchSubmit' , ( ) => {
@@ -2566,6 +2599,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
25662599
25672600 expect ( tracker . trackSearchResultsLoaded ( term , requiredParameters ) ) . to . equal ( true ) ;
25682601 } ) ;
2602+
2603+ it ( 'Should truncate url param to 2048 characters max' , ( done ) => {
2604+ const longUrl = createLongUrl ( 3000 ) ;
2605+ const truncatedUrl = longUrl . slice ( 0 , 2048 ) ;
2606+
2607+ const { tracker } = new ConstructorIO ( {
2608+ apiKey : testApiKey ,
2609+ fetch : fetchSpy ,
2610+ ...requestQueueOptions ,
2611+ } ) ;
2612+
2613+ tracker . on ( 'success' , ( ) => {
2614+ const requestParams = helpers . extractBodyParamsFromFetch ( fetchSpy ) ;
2615+
2616+ // Request
2617+ expect ( fetchSpy ) . to . have . been . called ;
2618+ expect ( requestParams . url ) . to . equal ( truncatedUrl ) ;
2619+
2620+ done ( ) ;
2621+ } ) ;
2622+
2623+ const parameters = {
2624+ ...requiredParameters ,
2625+ url : longUrl ,
2626+ } ;
2627+
2628+ expect ( tracker . trackSearchResultsLoaded ( term , parameters ) ) . to . equal ( true ) ;
2629+ } ) ;
25692630 } ) ;
25702631
25712632 describe ( 'trackSearchResultClick' , ( ) => {
@@ -4805,6 +4866,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
48054866
48064867 expect ( tracker . trackRecommendationView ( requiredParamsWithSeedItemIds ) ) . to . equal ( true ) ;
48074868 } ) ;
4869+
4870+ it ( 'Should truncate url param to 2048 characters max' , ( done ) => {
4871+ const longUrl = createLongUrl ( 3000 ) ;
4872+ const truncatedUrl = longUrl . slice ( 0 , 2048 ) ;
4873+
4874+ const { tracker } = new ConstructorIO ( {
4875+ apiKey : testApiKey ,
4876+ fetch : fetchSpy ,
4877+ ...requestQueueOptions ,
4878+ } ) ;
4879+
4880+ tracker . on ( 'success' , ( ) => {
4881+ const requestParams = helpers . extractBodyParamsFromFetch ( fetchSpy ) ;
4882+
4883+ // Request
4884+ expect ( fetchSpy ) . to . have . been . called ;
4885+ expect ( requestParams . url ) . to . equal ( truncatedUrl ) ;
4886+
4887+ done ( ) ;
4888+ } ) ;
4889+
4890+ const parameters = {
4891+ ...requiredParameters ,
4892+ url : longUrl ,
4893+ } ;
4894+
4895+ expect ( tracker . trackRecommendationView ( parameters ) ) . to . equal ( true ) ;
4896+ } ) ;
48084897 } ) ;
48094898
48104899 describe ( 'trackRecommendationClick' , ( ) => {
@@ -5696,6 +5785,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
56965785
56975786 expect ( tracker . trackBrowseResultsLoaded ( requiredParameters ) ) . to . equal ( true ) ;
56985787 } ) ;
5788+
5789+ it ( 'Should truncate url param to 2048 characters max' , ( done ) => {
5790+ const longUrl = createLongUrl ( 3000 ) ;
5791+ const truncatedUrl = longUrl . slice ( 0 , 2048 ) ;
5792+
5793+ const { tracker } = new ConstructorIO ( {
5794+ apiKey : testApiKey ,
5795+ fetch : fetchSpy ,
5796+ ...requestQueueOptions ,
5797+ } ) ;
5798+
5799+ tracker . on ( 'success' , ( ) => {
5800+ const requestParams = helpers . extractBodyParamsFromFetch ( fetchSpy ) ;
5801+
5802+ // Request
5803+ expect ( fetchSpy ) . to . have . been . called ;
5804+ expect ( requestParams . url ) . to . equal ( truncatedUrl ) ;
5805+
5806+ done ( ) ;
5807+ } ) ;
5808+
5809+ const parameters = {
5810+ ...requiredParameters ,
5811+ url : longUrl ,
5812+ } ;
5813+
5814+ expect ( tracker . trackBrowseResultsLoaded ( parameters ) ) . to . equal ( true ) ;
5815+ } ) ;
56995816 } ) ;
57005817
57015818 describe ( 'trackBrowseRedirect' , ( ) => {
@@ -7343,6 +7460,34 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
73437460
73447461 expect ( tracker . trackQuizResultsLoaded ( requiredParameters ) ) . to . equal ( true ) ;
73457462 } ) ;
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+ } ) ;
73467491 } ) ;
73477492
73487493 describe ( 'trackQuizResultClick' , ( ) => {
0 commit comments