I am using this code to store the referrer URL in my form for tracking conversions, the problem I have is that the URL it stores is the URL which the form is on and not the URL where the visitor came from.
I am trying to get the URL of the website that the user came from, i.e if the user came from google I need the URL to be google.
Here's my code;
function hiddenreferer_shortcode($tag) {
if ( ! is_array( $tag ) )
return '';
$options = (array) $tag['options'];
foreach ( $options as $option ) {
if ( preg_match( '%^name:([-0-9a-zA-Z_]+)$%', $option, $matches ) ) {
$name_att = $matches[1];
}
}
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$value_att = $pageURL;
$html = '<input type="hidden" name="' . $name_att . '" value="'.$value_att.'" />';
return $html;
}
// REFERER IN CONTACT FORM 7
wpcf7_add_shortcode('hiddenreferer', 'hiddenreferer_shortcode', true);