Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if a user came is an organic or direct visit?

Is it possible to determine whether a user has come to your website via an organic search or direct and is it then possible to store this in our database?

We have a form on our website so essentially we want to find out if the user came direct or via organic search and then pass this in with the form to store 'organic' or 'direct' in our database for each enquiry.

E.g if user ABC came via direct and filled in the form they would be stored in the database as name = ABC, referral = direct, enquiry = test.

If user XYZ came via organic and filled in the form they would be stored in the database as name = XYZ, referral = organic, enquiry = test.

like image 477
user1961082 Avatar asked Nov 01 '22 15:11

user1961082


2 Answers

You can use $_SERVER['HTTP_REFERER']

PHP DOCS: The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

http://php.net/manual/en/reserved.variables.server.php

like image 142
cmorrissey Avatar answered Nov 09 '22 07:11

cmorrissey


You could try to request the browsers "referrer" parameter. However, this method is extremely unreliable and is often unavailable. The best option would be to have a section (maybe even make it required) where the user selects where they come from.

The reason is what if they found your site on Google at work, then went home and manually typed in the URL? You would count it as a direct visit even though it was really a search engine. That's why most forms typically have a dropdown for this selection.

You could always grab both the referrer as well as their choice and use those for reporting.

Update: Since you mentioned you are tracking a PPC campaign, I have a few methods that you can use to better track the source.

The first method is to create a landing page for your ad to click over to. Basically, the page will be almost identical to the form on your website, but will instead be a standalone page or subdomain. This page will have a duplicate form that will have the referral value hard coded in. You could have a unique page/site for each campaign source (yoursite/google.aspx, yoursite.com/yahoo.aspx, etc.)

A second method would be to use a single form to take in the submission, but in your campaign assign a querystring variable that will represent the campaign (yourpage.aspx?r=google, yourpage.aspx?r=yahoo, etc.) Once the user loads the page, grab that querystring variable and save it in their session or in a cookie. That way if they browse your site and go back to the form, you would still have their referrer.

As always, these methods don't work if they click to your site from an ad and then manually type it in at home. This isn't super common but it does happen occasionally.

like image 38
Nicholas Post Avatar answered Nov 09 '22 05:11

Nicholas Post