SOLVED

Re: Capture GCLID On Website & Hidden Form

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: Capture GCLID On Website & Hidden Form

No need to change anything. Just use <script type="text/gtmscript"> instead of <script>.

mreillysalsify
Level 1

Re: Capture GCLID On Website & Hidden Form

Hi @SanfordWhiteman - I was reviewing this thread, and was curious if you knew the best method to set the cookie to expire at the end of the current browser session. Would setting "var  expiryPeriod = 0" effectively do that?

 

For context, after conferring with my Marketing team, we decided that we only want to attribute the ad click to conversions directly driven through that session, so there's no need to keep the cookie active for 90 day like you have set it up in your code.

 

Thank you for all that you do for the community Sanford!

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Capture GCLID On Website & Hidden Form

You can use this extended code: https://codepen.io/figureone/pen/bGqrNEp

 

Set storage to "sessionStorage".

mreillysalsify
Level 1

Re: Capture GCLID On Website & Hidden Form

Hi @SanfordWhiteman, this code is EXCELLENT! We're trying to extend this functionality to also capture standard UTM.
Our goal is to cookie utm_campaign, utm_source, utm_medium & utm_term values for the duration on the browser session to cover the use case when a paid source may bring someone to homepage, and/or the user doesn't immediately covert on page with the referral UTM link.
Would you recommend doing this with the same code, or do you have another set of code handle cookieing this info?

SanfordWhiteman
Level 10 - Community Moderator

Re: Capture GCLID On Website & Hidden Form


Would you recommend doing this with the same code, or do you have another set of code handle cookieing this info?

You can’t do that with this same lightweight Auto-Fill code. There’s a whole other codebase we use for that.

mreillysalsify
Level 1

Re: Capture GCLID On Website & Hidden Form

@SanfordWhiteman Is that codebase proprietary or are you willing to share with the community?

SanfordWhiteman
Level 10 - Community Moderator

Re: Capture GCLID On Website & Hidden Form


 Is that codebase proprietary or are you willing to share with the community?

It’s not proprietary (in the sense of not allowed to be used by other parties) yet I’m unable to share it due to Community rules.

MasonWild
Level 1

Re: Capture GCLID On Website & Hidden Form

Thanks for supplying the script. Please could you let me know how to configure the new field within the form to ensure the GCLID is passed through correctly?

 

Thanks,

Mason

Jo_Pitts1
Level 10 - Community Advisor

Re: Capture GCLID On Website & Hidden Form

@MasonWild ,

you don't need to add the field to the form.  @SanfordWhiteman's code adds the field behind the scenes.

 

All you need to do is know the SOAP name of the field you are storing the GCLID in, and update this code here:

      // (SOAP) name of your form field
      const gclidFormFieldName = "MostRecentGclid";

Change MostRecentGclid to whatever field name you want to store the most recent GCLID in.

 

Cheers

Jo

 

MasonWild
Level 1

Re: Capture GCLID On Website & Hidden Form

Very helpful!   

 

I've managed to do some further testing and it seems to be working successfully.