@@ -2,7 +2,8 @@ import CookieSyncManager, {
22 DAYS_IN_MILLISECONDS ,
33 IPixelConfiguration ,
44 CookieSyncDates ,
5- isLastSyncDateExpired
5+ isLastSyncDateExpired ,
6+ PARTNER_MODULE_IDS
67} from '../../src/cookieSyncManager' ;
78import { IMParticleWebSDKInstance } from '../../src/mp-instance' ;
89import { testMPID } from '../src/config/constants' ;
@@ -425,6 +426,217 @@ describe('CookieSyncManager', () => {
425426
426427 expect ( cookieSyncManager . performCookieSync ) . not . toHaveBeenCalled ( ) ;
427428 } ) ;
429+
430+ describe ( 'Trade Desk domain parameter' , ( ) => {
431+ const originalLocation = window . location ;
432+
433+ beforeEach ( ( ) => {
434+ // Mock window.location.hostname
435+ delete ( window as any ) . location ;
436+ ( window as any ) . location = { ...originalLocation , hostname : 'example.com' } ;
437+ } ) ;
438+
439+ afterEach ( ( ) => {
440+ ( window as any ) . location = originalLocation ;
441+ } ) ;
442+
443+ it ( 'should add domain parameter for Trade Desk (module ID 103)' , ( ) => {
444+ const tradeDeskPixelSettings : IPixelConfiguration = {
445+ ...pixelSettings ,
446+ moduleId : PARTNER_MODULE_IDS . TradeDesk , // 103
447+ pixelUrl : 'https://insight.adsrvr.org/track/up?adv=abc123' ,
448+ redirectUrl : '' ,
449+ } ;
450+
451+ const mockMPInstance = ( {
452+ _Store : {
453+ webviewBridgeEnabled : false ,
454+ pixelConfigurations : [ tradeDeskPixelSettings ] ,
455+ } ,
456+ _Persistence : {
457+ getPersistence : ( ) => ( { testMPID : {
458+ csd : { }
459+ } } ) ,
460+ } ,
461+ _Consent : {
462+ isEnabledForUserConsent : jest . fn ( ) . mockReturnValue ( true ) ,
463+ } ,
464+ Identity : {
465+ getCurrentUser : jest . fn ( ) . mockReturnValue ( {
466+ getMPID : ( ) => testMPID ,
467+ } ) ,
468+ } ,
469+ } as unknown ) as IMParticleWebSDKInstance ;
470+
471+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
472+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
473+
474+ cookieSyncManager . attemptCookieSync ( testMPID , true ) ;
475+
476+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
477+ 'https://insight.adsrvr.org/track/up?adv=abc123&domain=example.com' ,
478+ '103' ,
479+ testMPID ,
480+ { } ,
481+ ) ;
482+ } ) ;
483+
484+ it ( 'should not add domain parameter for non-Trade Desk partners' , ( ) => {
485+ const nonTradeDeskPixelSettings : IPixelConfiguration = {
486+ ...pixelSettings ,
487+ moduleId : PARTNER_MODULE_IDS . AppNexus , // 50
488+ pixelUrl : 'https://ib.adnxs.com/cookie_sync?adv=abc123' ,
489+ redirectUrl : '' ,
490+ } ;
491+
492+ const mockMPInstance = ( {
493+ _Store : {
494+ webviewBridgeEnabled : false ,
495+ pixelConfigurations : [ nonTradeDeskPixelSettings ] ,
496+ } ,
497+ _Persistence : {
498+ getPersistence : ( ) => ( { testMPID : {
499+ csd : { }
500+ } } ) ,
501+ } ,
502+ _Consent : {
503+ isEnabledForUserConsent : jest . fn ( ) . mockReturnValue ( true ) ,
504+ } ,
505+ Identity : {
506+ getCurrentUser : jest . fn ( ) . mockReturnValue ( {
507+ getMPID : ( ) => testMPID ,
508+ } ) ,
509+ } ,
510+ } as unknown ) as IMParticleWebSDKInstance ;
511+
512+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
513+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
514+
515+ cookieSyncManager . attemptCookieSync ( testMPID , true ) ;
516+
517+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
518+ 'https://ib.adnxs.com/cookie_sync?adv=abc123' ,
519+ '50' ,
520+ testMPID ,
521+ { } ,
522+ ) ;
523+ } ) ;
524+
525+ it ( 'should handle multiple pixel configurations with mixed Trade Desk and non-Trade Desk' , ( ) => {
526+ const tradeDeskPixelSettings : IPixelConfiguration = {
527+ ...pixelSettings ,
528+ moduleId : PARTNER_MODULE_IDS . TradeDesk ,
529+ pixelUrl : 'https://insight.adsrvr.org/track/up?adv=ttd123' ,
530+ redirectUrl : '' ,
531+ } ;
532+
533+ const appNexusPixelSettings : IPixelConfiguration = {
534+ ...pixelSettings ,
535+ moduleId : PARTNER_MODULE_IDS . AppNexus ,
536+ pixelUrl : 'https://ib.adnxs.com/cookie_sync?adv=anx123' ,
537+ redirectUrl : '' ,
538+ } ;
539+
540+ const mockMPInstance = ( {
541+ _Store : {
542+ webviewBridgeEnabled : false ,
543+ pixelConfigurations : [ tradeDeskPixelSettings , appNexusPixelSettings ] ,
544+ } ,
545+ _Persistence : {
546+ getPersistence : ( ) => ( { testMPID : {
547+ csd : { }
548+ } } ) ,
549+ } ,
550+ _Consent : {
551+ isEnabledForUserConsent : jest . fn ( ) . mockReturnValue ( true ) ,
552+ } ,
553+ Identity : {
554+ getCurrentUser : jest . fn ( ) . mockReturnValue ( {
555+ getMPID : ( ) => testMPID ,
556+ } ) ,
557+ } ,
558+ } as unknown ) as IMParticleWebSDKInstance ;
559+
560+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
561+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
562+
563+ cookieSyncManager . attemptCookieSync ( testMPID , true ) ;
564+
565+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledTimes ( 2 ) ;
566+
567+ // Check Trade Desk call (with domain)
568+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
569+ 'https://insight.adsrvr.org/track/up?adv=ttd123&domain=example.com' ,
570+ '103' ,
571+ testMPID ,
572+ { } ,
573+ ) ;
574+
575+ // Check AppNexus call (without domain)
576+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
577+ 'https://ib.adnxs.com/cookie_sync?adv=anx123' ,
578+ '50' ,
579+ testMPID ,
580+ { } ,
581+ ) ;
582+ } ) ;
583+
584+ it ( 'should handle domain parameter with hyphens and subdomains' , ( ) => {
585+ // Mock a hostname with hyphens and subdomains
586+ delete ( window as any ) . location ;
587+ ( window as any ) . location = { ...originalLocation , hostname : 'sub-domain.example.com' } ;
588+
589+ const tradeDeskPixelSettings : IPixelConfiguration = {
590+ ...pixelSettings ,
591+ moduleId : PARTNER_MODULE_IDS . TradeDesk ,
592+ pixelUrl : 'https://insight.adsrvr.org/track/up' ,
593+ redirectUrl : '' ,
594+ } ;
595+
596+ const mockMPInstance = ( {
597+ _Store : {
598+ webviewBridgeEnabled : false ,
599+ pixelConfigurations : [ tradeDeskPixelSettings ] ,
600+ } ,
601+ _Persistence : {
602+ getPersistence : ( ) => ( { testMPID : {
603+ csd : { }
604+ } } ) ,
605+ } ,
606+ _Consent : {
607+ isEnabledForUserConsent : jest . fn ( ) . mockReturnValue ( true ) ,
608+ } ,
609+ Identity : {
610+ getCurrentUser : jest . fn ( ) . mockReturnValue ( {
611+ getMPID : ( ) => testMPID ,
612+ } ) ,
613+ } ,
614+ } as unknown ) as IMParticleWebSDKInstance ;
615+
616+ const cookieSyncManager = new CookieSyncManager ( mockMPInstance ) ;
617+ cookieSyncManager . performCookieSync = jest . fn ( ) ;
618+
619+ cookieSyncManager . attemptCookieSync ( testMPID , true ) ;
620+
621+ expect ( cookieSyncManager . performCookieSync ) . toHaveBeenCalledWith (
622+ 'https://insight.adsrvr.org/track/up?domain=sub-domain.example.com' ,
623+ '103' ,
624+ testMPID ,
625+ { } ,
626+ ) ;
627+ } ) ;
628+ } ) ;
629+ } ) ;
630+
631+ describe ( 'PARTNER_MODULE_IDS' , ( ) => {
632+ it ( 'should contain all expected partner module IDs' , ( ) => {
633+ expect ( PARTNER_MODULE_IDS . AdobeEventForwarder ) . toBe ( 11 ) ;
634+ expect ( PARTNER_MODULE_IDS . DoubleclickDFP ) . toBe ( 41 ) ;
635+ expect ( PARTNER_MODULE_IDS . AppNexus ) . toBe ( 50 ) ;
636+ expect ( PARTNER_MODULE_IDS . Lotame ) . toBe ( 58 ) ;
637+ expect ( PARTNER_MODULE_IDS . TradeDesk ) . toBe ( 103 ) ;
638+ expect ( PARTNER_MODULE_IDS . VerizonMedia ) . toBe ( 155 ) ;
639+ } ) ;
428640 } ) ;
429641
430642 describe ( '#performCookieSync' , ( ) => {
0 commit comments