-
-
Save netconstructor/2567176 to your computer and use it in GitHub Desktop.
Add referring site to Gravity Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment