Can we capture HTTP REFERER information upon form submission using Contact Form 7?

Definitely.

Situation: A CTA button labeled “Get Pricing” is on all product pages of a website and clicking it takes you to a dedicated page that has a form generated by Contact Form 7 plugin. You wish to capture the page the visitor was on upon form submission and here is how I have accomplished it.

1. Add a Text Field element with a css class referer-page

[ text referer-page class:referer-page]

2. Add the following css to your styles.css

input.referer-page { display:none; }

3. Add the following code snippets to your functions.php

function getRefererPage( $form_tag )
{
	if ( $form_tag['name'] == 'referer-page' ) {
		$form_tag['values'][] = $_SERVER['HTTP_REFERER'];
	}
	return $form_tag;
}
if ( !is_admin() ) {
        add_filter( 'wpcf7_form_tag', 'getRefererPage' );
}

4. Add the following to the Contact Form 7 Message body (under Mail)

Referer Page: [referer-page]

That’s it!

Loading Facebook Comments ...

18 thoughts on “Can we capture HTTP REFERER information upon form submission using Contact Form 7?”

  1. this works great, however, i have one problem. when the person comes directly to the form from an outside url the code works great. but, when they come to the site and travel a few pages, the referring url seems to be lost. is this a cookie issue?

    can something be done to keep the referring url in-tacked?

  2. Hey Tony, thanks for posting this blog.

    If you’ve got a sec, do you know how I could pass the website or referrer url the visitor was on before landing on this site during the session?

    I want that sent with the form to me so that I can track where contacts are coming from.

    Thanks a bunch for your help!

    Kenn

    1. Kenn,

      I believe google analytics can do this for you. I’d first setup contact form 7 to track form submissions. Then setup goals, goal values in your google analytics account. Once google analytics starts tracking these goals, you will be able to see where the leads come from by going to Conversions -> Goals -> Overview -> Goals -> Goal Completion URL -> Source/Medium. To further track the actual urls, you can go to Traffic Sources -> Incoming Sources -> Referals. (I’d click on Explorer -> Goal Set 1 which reveals some numbers) There are some knobs you can play with so I’d suggest that you try them out.

      BTW… I have forgotten to mention that you will need to switch to the New Version of the analytics.

  3. Hi, nice tutorial…
    But i still newbie and need little help here…

    I’m making a simple web shop and plans to use the contact form 7 as a place to order.

    Plan:

    1. Creating the “Buy Now” button on each product.

    2. If the button is clicked, then the client will automatically redirected to the contact form 7 page with the subject “title post / Product name.”

    3. Post titles/Product name could not be edited.

    How i can make like that?

    If you help, I would greatly appreciate it.

    Thanks.

  4. if you’re using google conversion tracker and bouncing out to another page when the form is sent it returns the conversion page i.e http………/form-sent/ any thoughts on how I can get around that. Other than that this works a treat!! :) thanks heaps

  5. Awesome! Is what I was looking for a lifetime!
    I have made you one question, how do I prevent users from changing the field ?

  6. Hello, I can not get the field to hide. The css was added to my themes custom css options so that I did not have to directly add it to the style.css. Should I add it directly to the style.css? Or are you instructing to create a new file called styles.css?

    The class seems to show as class=”wpcf7-form-control wpcf7-text referer-page”.

    No matter what I do, it will not hide the text field.

Leave a Reply