6

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.

JJJ
  • 32,902
  • 20
  • 89
  • 102
user1961082
  • 1,015
  • 17
  • 41

3 Answers3

1

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.

Nicholas Post
  • 1,857
  • 1
  • 18
  • 31
  • Thanks but we can't really ask. It's more to monitor if people are coming via direct or organic to monitor SEO, PPC etc but we don't really want to ask the question. – user1961082 Sep 04 '13 at 16:44
  • Updated to add a couple methods for tracking PPC. – Nicholas Post Sep 04 '13 at 17:24
  • Thanks Nicholas. It's not specifically to track PPC customers and it also needs to track on any page i.e if they land on the home page, then go to the about us page then go to the form page and fill it in. We'd want to determine if they were a paid visit or organic. – user1961082 Sep 05 '13 at 08:57
  • That is why I said in my reply to use a session object or cookie to hold their source. This would be able to provide just that. – Nicholas Post Sep 05 '13 at 10:59
1

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

cmorrissey
  • 8,493
  • 2
  • 23
  • 27
  • 1
    http://stackoverflow.com/questions/6880659/in-what-cases-will-http-referer-be-empty explains a few situations that this information may be blocked. – Nicholas Post Sep 04 '13 at 16:46
  • Thanks. Im currently looking at the function at the bottom of this page. http://stackoverflow.com/questions/18238524/php-ga-how-to-identify-organic-traffic Would you say this is at least 90% accurate based on the link you sent me? Either way, we're not going to get 100% accuracy are we? – user1961082 Sep 04 '13 at 16:57
  • I tried tracking this information a while back, but no longer have access to the database. I know the actual results caught were quite a bit lower than 90%. I will update my answer to reflect a different method. – Nicholas Post Sep 04 '13 at 17:18
  • is the true only way to do this is by using canonical links with parameters for search engines?? – oldboy Jul 25 '19 at 08:20
0

As I understand it, you are trying to pass a value stored within the GA cookie to your CRM database. If so, there are a number of ways you could accomplish what you are looking for.

Like others have said, I would recommend parsing the data from the cookie. There's also the _link() or for you, the _linkByPost() function which will append the cookie information as URL parameters. Perhaps then you could take the values from the URL parameters: https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiDomainDirectory#_gat.GA_Tracker_._linkByPost

In this case, you would have a script on the form confirmation URL that would listen to the URL parameters than contain referrer information, and pass that along to your database. Here is an example of what that URL would look like:

www.example.com?__utma=224048396.1415920582.1378332727.1378332727.1378332727.1&__utmb=224048396.2.10.1378332727&__utmc=224048396&__utmx=-&__utmz=224048396.1378332727.1.1.utmcsr=stackoverflow.com|utmccn=(referral)|utmcmd=referral|utmcct=/forum/&__utmv=-&__utmk=125169161

Have you considered using the API? That might be another option. Check out this API tool, it's quite helpful: http://ga-dev-tools.appspot.com/explorer/.

Can you provide a snippet of the code that's storing the values associated with a given user?

MMMdata
  • 817
  • 8
  • 19
  • Yes that's what we're trying to do (unless there is a way to tell if it is an organic or paid visit without GA?!). We'd need to be able to pass it to the db before the confirmation page. We simply have a form that asks for name, email, telephone number and enquiry. We store these in a MySQL database and want to just tag 'organic' or 'direct' with each value stored. – user1961082 Sep 05 '13 at 09:01
  • Well if it's a paid visit, you can control the URL you direct people to, and either using autotagging - www.example.com/?gclid=1234567890, or using UTM parameters - www.example.com/?utm_source=google&utm_medium=cpc&utm_term=widgets&utm_campaign=widget-sale-2013 How are you adding customer info to your database before they supply it with the form? Are you adding everyone to your database regardless of a form submission? – MMMdata Sep 05 '13 at 15:49
  • No, I'm only concerned with those who submit the form. Other users don't matter. – user1961082 Sep 06 '13 at 14:03