Software

Contact Form 7 Referral url for tracking info

cont7

Hello Fellas, Most of the time, site owner wants to know the source of page, from where user landed on contact page. This would be very useful if someone is using contact link on every of your product page, or real estate property page. Or you have call to action on several pages / posts and you wanna know from where user clicked on contact us page.

This code will go into your style sheet

input.referer-page { 

         display:none; 

}

This needs to go in your theme’s functions.php file.

 //--------------- Referer code for contact form 7
function getIP() {
 
    $sProxy = '';
    if ( getenv( 'HTTP_CLIENT_IP' ) ) {
        $sProxy = $_SERVER['REMOTE_ADDR'];
        $sIP    = getenv( 'HTTP_CLIENT_IP' ) ;
    } elseif( $_SERVER['HTTP_X_FORWARDED_FOR'] ) {
        $sProxy = $_SERVER['REMOTE_ADDR'];
        $sIP    = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $sIP    = $_SERVER['REMOTE_ADDR'];
    }
    if ( ! empty( $sProxy ) ) {
        $sIP = $sIP . 'via-proxy:' . $sProxy;
    }
    return $sIP;
}
 
function setRefererTransient( $uniqueID ) {
    if ( false === ( $void = get_transient( $uniqueID ) ) ) {
        // set a transient for 2 hours
        set_transient( $uniqueID, $_SERVER['HTTP_REFERER'], 60*60*2 );
    }
}
 
function getRefererPage( $form_tag ) {
    if ( $form_tag['name'] == 'referer-page' ) {
        $uniqueID = getIP();
        setRefererTransient( $uniqueID );
        $form_tag['values'][] =  isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Referral Not Available';
    }
    return $form_tag;
}
 
if ( !is_admin() ) {
    add_filter( 'wpcf7_form_tag', 'getRefererPage' );
}

This shortcode needs to go in your contact form side:


[ text referer-page ]

This need to go in email setting of the contact form 7

[referer-page]

If you get any problem, make sure you verify to have latest contact form 7 plugin. Or write me comments or contact me.

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button
Close
Close