@@ -81,4 +81,72 @@ describe('EnhanceAffiliateLinks', () => {
8181 'xcust=referrer%7Cfoo.com%7CaccountId%7C12345%7CabTestParticipations%7Ctest1%3AvariantA%2Ctest2%3AvariantB' ,
8282 ) ;
8383 } ) ;
84+
85+ it ( 'should use article URL UTM parameters when present' , ( ) => {
86+ Object . defineProperty ( window , 'location' , {
87+ value : new URL (
88+ 'https://example.test/this?utm_source=growth&utm_medium=epicuk&utm_campaign=q3_test&utm_content=filter_general' ,
89+ ) ,
90+ configurable : true ,
91+ } ) ;
92+
93+ document . body . innerHTML = `<a href="https://go.skimresources.com/?id=12345">Skimlink</a>` ;
94+
95+ render ( < EnhanceAffiliateLinks /> ) ;
96+
97+ const link = document . querySelector ( 'a' ) ;
98+ expect ( link ?. href ) . toContain (
99+ 'utm_source%7Cgrowth%7Cutm_medium%7Cepicuk%7Cutm_campaign%7Cq3_test%7Cutm_content%7Cfilter_general' ,
100+ ) ;
101+ } ) ;
102+
103+ it ( 'should use UTM parameters from the referrer if the article URL has none' , ( ) => {
104+ Object . defineProperty ( window , 'location' , {
105+ value : new URL ( 'https://example.test/page' ) ,
106+ configurable : true ,
107+ } ) ;
108+
109+ Object . defineProperty ( document , 'referrer' , {
110+ value : 'https://foo.bar/some?utm_source=testsource&utm_medium=somemedium&utm_campaign=refcamp' ,
111+ configurable : true ,
112+ } ) ;
113+
114+ document . body . innerHTML = `
115+ <a href="https://go.skimresources.com/?id=12345">Skimlink</a>
116+ ` ;
117+
118+ render ( < EnhanceAffiliateLinks /> ) ;
119+
120+ const link = document . querySelector ( 'a' ) ;
121+
122+ expect ( link ?. href ) . toContain (
123+ 'utm_source%7Ctestsource%7Cutm_medium%7Csomemedium%7Cutm_campaign%7Crefcamp' ,
124+ ) ;
125+ } ) ;
126+
127+ it ( 'should use UTM parameters from the article URL over the referrer if both exist' , ( ) => {
128+ Object . defineProperty ( window , 'location' , {
129+ value : new URL (
130+ 'https://example.test/page?utm_source=pagegrow&utm_medium=somemedium' ,
131+ ) ,
132+ configurable : true ,
133+ } ) ;
134+
135+ Object . defineProperty ( document , 'referrer' , {
136+ value : 'https://foo.bar?utm_source=refgrow&utm_medium=refmed' ,
137+ configurable : true ,
138+ } ) ;
139+
140+ document . body . innerHTML = `
141+ <a href="https://go.skimresources.com/?id=12345">Skimlink</a>
142+ ` ;
143+
144+ render ( < EnhanceAffiliateLinks /> ) ;
145+
146+ const link = document . querySelector ( 'a' ) ;
147+ expect ( link ?. href ) . toContain (
148+ 'utm_source%7Cpagegrow%7Cutm_medium%7Csomemedium' ,
149+ ) ;
150+ expect ( link ?. href ) . not . toContain ( 'refgrow' ) ;
151+ } ) ;
84152} ) ;
0 commit comments