@@ -81,6 +81,12 @@ <h2>{{ modalDescription }}</h2>
8181 </ label >
8282 </ div >
8383 < input type ="hidden " name ="_next " value ="/docs/contact-us-thanks/ ">
84+ < input type ="hidden " name ="utm_source-popup " id ="utm_source-popup ">
85+ < input type ="hidden " name ="utm_medium-popup " id ="utm_medium-popup ">
86+ < input type ="hidden " name ="utm_campaign-popup " id ="utm_campaign-popup ">
87+ < input type ="hidden " name ="utm_term-popup " id ="utm_term-popup ">
88+ < input type ="hidden " name ="utm_content-popup " id ="utm_content-popup ">
89+ < input type ="hidden " name ="client_id-popup " id ="client_id-popup ">
8490 < input type ="text " name ="_gotcha " style ="display:none ">
8591 </ div >
8692 < div class ="submit-button-container ">
@@ -120,6 +126,44 @@ <h2>{{ modalDescription }}</h2>
120126 }
121127 } ) ;
122128
129+ function populateUTMandClientIdFields ( ) {
130+ var $form = $ ( '.contact-form' ) ;
131+ if ( ! $form . length ) return ;
132+
133+ const utmKeys = [ 'utm_source' , 'utm_medium' , 'utm_campaign' , 'utm_term' , 'utm_content' ] ;
134+ const utmData = { } ;
135+
136+ utmKeys . forEach ( function ( key ) {
137+ let value = getURLParam ( key ) ;
138+ if ( value ) {
139+ localStorage . setItem ( key , value ) ;
140+ } else {
141+ value = localStorage . getItem ( key ) ;
142+ }
143+
144+ if ( value ) {
145+ value = decodeURIComponent ( value ) ;
146+ utmData [ key ] = value ;
147+ $form . find ( 'input[name="' + key + '-popup"]' ) . val ( value ) ;
148+ }
149+ } ) ;
150+
151+ const gaCookie = document . cookie . split ( '; ' ) . find ( row => row . startsWith ( '_ga=' ) ) ;
152+ if ( gaCookie ) {
153+ const parts = gaCookie . split ( '.' ) ;
154+ if ( parts . length >= 4 ) {
155+ const clientId = parts [ 2 ] + '.' + parts [ 3 ] ;
156+ utmData [ 'client_id' ] = clientId ;
157+ $form . find ( 'input[name="client_id-popup"]' ) . val ( clientId ) ;
158+ }
159+ }
160+ window . dataLayer = window . dataLayer || [ ] ;
161+ window . dataLayer . push ( {
162+ event : 'contact-us' ,
163+ ...utmData
164+ } ) ;
165+ }
166+
123167 jqueryDefer (
124168 function ( ) {
125169 $ ( document ) . ready ( function ( ) {
@@ -128,6 +172,7 @@ <h2>{{ modalDescription }}</h2>
128172 /* $('html, body').animate({
129173 scrollTop: $('#contact-form').offset().top - 200
130174 }, 0);*/
175+ populateUTMandClientIdFields ( ) ;
131176 $contactForm . find ( '.form-element .form-control' ) . addClass ( "input--empty" ) ;
132177 $contactForm . find ( '.form-element .form-control' ) . on ( 'input' , function ( ) {
133178 if ( ! $ ( this ) . val ( ) ) {
@@ -206,6 +251,11 @@ <h2>{{ modalDescription }}</h2>
206251 }
207252 }
208253
254+ function getURLParam ( name ) {
255+ const results = new RegExp ( '[?&]' + name + '=([^&#]*)' ) . exec ( window . location . href ) ;
256+ return results ? decodeURIComponent ( results [ 1 ] . replace ( / \+ / g, ' ' ) ) : null ;
257+ }
258+
209259 function validateContactForm ( form ) {
210260 let isValid = true ;
211261 const fieldsToValidate = [
0 commit comments