Skip to content

Instantly share code, notes, and snippets.

@norcross
Created March 30, 2012 18:00
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save norcross/2253445 to your computer and use it in GitHub Desktop.
Save norcross/2253445 to your computer and use it in GitHub Desktop.
Add referring site to Gravity Forms
function rkv_referr_source() { ?>
<script type="text/javascript">
// build function for cookie process
function rkv_grab_cookie() {
// check document referrer
if (document.referrer !== '')
var rkv_val = document.referrer;
else
var rkv_val = 'unknown';
// set cookie variables and clean URL
var rkv_name = 'rkv_ref';
var rkv_str = rkv_name + '=' + encodeURI(rkv_val);
// check for cookie
var rkv_chk = document.cookie.match('(^|;) ?' + rkv_name + '=([^;]*)(;|$)');
// add the cookie if none exists
if (!rkv_chk)
document.cookie = rkv_str;
}
// call cookie function
rkv_grab_cookie();
</script>
<?php }
add_action('wp_head', 'rkv_referr_source');
function rkv_referrer_formdata($data) {
// grab cookie if it exists
$ref_source = $_COOKIE['rkv_ref'];
// add cookie to form
$data['notification']['message'] .= "\r\nReferrer Source:\r\n".$ref_source;
// return referrer source and add to form
return $data;
}
add_filter('gform_pre_submission_filter', 'rkv_referrer_formdata');
@blakejnolan
Copy link

Where do I add this code? Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment