Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@blakejnolan blakejnolan commented Aug 19, 2014

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