# Add referral data into hidden form fields

**URL:** <https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446>\
**Category:** Get Help\
**Tags:** cookies, crm, auto-populate, dynamic-population, has-ticket\
**Created:** [September 16, 2022, 2:45pm UTC](https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446 "2022-09-16T14:45:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![user5da84ac592673520](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5da84ac592673520/32/1086_2.png) [@user5da84ac592673520](https://community.gravityforms.com/u/user5da84ac592673520)\
**Post date:** [September 16, 2022, 2:45pm UTC](https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446/1 "2022-09-16T14:45:06Z")

</div>

Hi,  
I want to add first refer, source etc to hidden form fields so I can connect this in the crm to individual submissions.  
With the help of this great tutorial [How To Add UTM And Referrer Information To Lead Forms? | Terminus Blog](https://www.terminusapp.com/blog/add-utm-referrer-lead-forms/) I get the cookies in the browser for par example:

\_uc\_referrer  
\_uc\_last\_referrer  
\_uc\_visits  
and the more usual suspects codes like:  
\_uc\_utm\_source  
\_uc\_utm\_campaign

In the tutorial there is an example how to get the data into mailchimp.  
Anywone an idea how to get these cookie data it into grafity form hidden fields?  
I found a clue here [Enrich Form Submission Data with Google Tag Manager - Analytics Mania](https://www.analyticsmania.com/post/enrich-form-submission-data-with-google-tag-manager/) I can get the terminus first party cookie in the site. I can pick them up as variables in GTM, but need a clue how to get first party cookies into hidden fields OR get GTM varables into gravity hidden fields…

I found this [https://docs.gravityforms.com/gform\_field\_value\_parameter\_name/#h-populate-from-a-cookie](https://docs.gravityforms.com/gform_field_value_parameter_name/#h-populate-from-a-cookie)

```auto
add_filter( 'gform_field_value_utm_campaign', 'populate_utm_campaign' );
function populate_utm_campaign( $value ) {
   return $_COOKIE['utm_campaign'];
}

```

cookie name =\_uc\_referrer  
form fiedl name = Initial REFERRER  
And the parameter name for dynamicpupulate =\_uc\_referrer

What should the code be?

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [September 19, 2022, 1:28pm UTC](https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446/2 "2022-09-19T13:28:27Z")

</div>

In the documentation example utm\_campaign is the name of the parameter configured in the field and also the name of the cookie, you’re doing the same, using the cookie name as parameter name, so simply replace all occurrences of **utm\_campaign** in the example with **\_uc\_referrer**

---

<div class="post-metadata">

**Author:** ![user5da84ac592673520](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/user5da84ac592673520/32/1086_2.png) [@user5da84ac592673520](https://community.gravityforms.com/u/user5da84ac592673520)\
**Post date:** [September 23, 2022, 12:07pm UTC](https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446/3 "2022-09-23T12:07:05Z")

</div>

Thank you. I got it working. But on Iphone its not working. I assume Safari blocks the cookie collection?  
Anyway; is thee a comparable way to populate field from the DataLayer?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [October 23, 2022, 12:07pm UTC](https://community.gravityforms.com/t/add-referral-data-into-hidden-form-fields/13446/4 "2022-10-23T12:07:34Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
