Tracking URL and Keyword in PHP

by 30 replies
37
I have asked my web designer to track the URL and Keyword for each click coming from my Adwords campaigns usin the HTTP_REFERRER variable but he seems to think that when my online form is submitted, it will only track the last URL.

Can someone who has PHP experience please give me a short briefing on what I should be telling my programmer to enable him to capture the first URL when a user enters my site from a campaign so that we can assign the URL + Keyword to each form submission.

The reasoning for this is that it will enable me to track what keywords from my my website leads convert to actual deals!

Thanks
#programming #keyword #php #tracking #url
  • Your programmer is right, the formal definition of the $_SERVER['HTTP_REFERER'] variable is the following: "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."

    So, yes, the "HTTP_REFERER" only tracks the last URL.

    However, there is a simple way around it. When users come to your website, check if they already have the cookie "first_http_referer" and if they don't have it, set the value of the cookie "first_http_referer" to $_SERVER['HTTP_REFERER'].

    This way you will always have the information you want saved in user's cookie - and the information won't get overwriten as your user continues to browse around your website.

    I hope I've helped you with my reply.

    Aaron
    • [1] reply
    • Splinter,

      If you want to track the AdWords info when a from is submitted you will probably need to do it using javascript.

      window.document.referrer - will get the URL and
      window.location.search - will get you the query string

      The you can place these using javascript as a hidden input and when form is submitted the info will be passed.

      Also, this does not rely on cookies.

      Your programmer should know the details on how to do this.

      Hope that helps,
      Rodney
      • [1] reply
  • Splinter,

    That code looks fine. However, you are going to miss visitors who are not accepting cookies. Also you have to be sure and set those session cookies before anything is written to browser.

    You said when form submitted, so your script for processing form reads the cookies. The method I mentioned lets you pass the data with the form and will work even if cookies are not enabled. If your form uses post method then values will be in $_POST global array with key having whatever name you used in the hidden input elements.

    Assume you used URL and KW then $_POST['URL'] would replace $URL in your script and $_POST['KW'] would replace $query.

    Rodney
    • [ 1 ] Thanks
    • [2] replies
    • Thanks Rodney, I will swing this past my chap and ask him to make the necessary amendments.
    • Hi Rodney, can you please comment on my programmers reply below. If it is only 5% of users that do not have cookies enabled, it is probably not worth it for the amount of work that is entailed.

      ====================










      • [1] reply
  • Perhaps I am misunderstanding but doesn't Google Analytics have this capability?
    • [1] reply
    • Not entirely for what I want it for as I want to track what keywords are being typed by each lead which is submitted to me via a form. Then of these leads, a very small % convert into deals so again I can track which keywords are mainly converting to deals.

      Analytics will therefore not associate the keyword being used to a specific lead.

      Hope that answers your Q
  • I see,
    This would not be much different than tracking in a shopping cart.
    The original referer can be parsed as mentioned above, the IP can be captured, an ID assigned, and all of the info logged in your database when a person first visits the site. The ID can be set to follow them around via a query string if cookies are not used. Any action that this person makes can then be recorded.
    If that person submits the form their record is updated. If they convert then the record is further updated.
    If URLs on your site are dynamically created, assigning the user id would be simple enough. If not then you would have your work cut out for you if your site is very large.

    Or you could always ask the person what the keywords used were as part of your conversion process.
    • [1] reply
    • HomeComputerGames, thanks for showing me another way it can be done. The site is not that large so we have decided to just track it be capturing the URL and Q string on the users first visit via a cookie. If they do not have cookies enabled, we will loose out however I think the amount of times this will happen will be so far and few between.

      Should it become a problem, the idea you have just mentioned along with a couple others above would have to be implemented.
  • The more I think about it can you not just match ip's and dates in a report pulled from your server logs?
    You should be able to log just about anything needed via your server.
    So writing custom reports pulling from these logs may work best by matching IP and date. If %page entry% exists run the report.

    Then parse the First referrer entry for this IP + date for your keywords.
  • That is a bit too techie for me. I will run it past my friend who looks after all the IT stuff for me. Thanks
    • [1] reply
    • I've also been looking for the same solution for a while, and found the following:
      Best Contact Form - Features
      Seems these guys have cracked it, but it's a hosted service that costs a little too much.

      So the knowledge is out there, so hope someone will share someday :-)

      - Vince
  • This is an interesting thread!

    I wish the [ php ] tags were working.
  • Banned
    [DELETED]
  • It is not a good idea to track by IP address because it is not necessarily unique to a user. That is, an IP address that is seen at your site can be sured by multiple users. For example, I am in a hotel on local address 192.168.0.99 but every room in the hotel is going out to the web on the same IP. It works better just to assign a unique id generated using md5 and place in cookie.

    Another interesting way to track is using flash shared objects. They actually work, per Adobe's report, on 99% of browsers and are much harder to delete than cookies and cannot be turned off like cookies.

    Rodney
    • [1] reply
    • Just to let you guys know, we went live with our new site this weekend and our first few leads have come in all with the URL and keywords. So it is working but we will monitor to see if and how many come in with a blank field.
      • [1] reply
  • You shouldn't be usin' referrers for this anyway. You won't always get one, and what they searched isn't the keyword you bid on, so you will have trouble tieing the referrers back to what keywords to eliminate or spend more on with your AdWords account.

    Instead tell Google to pass in the keyword that was matched to your landing page as part of the URL.

    Use {keyword} in the destination URL of the ad.

    Ex: http://www.your-domain.com/some-page.php?kw={keyword}

    Then you can read the keyword that the user's search matched from $_GET['kw'].

    Or use a proper tracking system like Google Analytics, or the one I'm releasing this month, to track this kinda thing without having your programmer reinvent the wheel.
    • [1] reply
    • Dan surely what I am doing is matching the keyword to the Q string. Each time a form submission comes through, as part of the email we are sent the HTTP Referrer which includes the keyword. There has been maybe a couple out of a few hundred leads which has not had the keyword so it seems to be fairly accurate.

      Now when a lead converts into a purchase (deal), we can start matching what are the real converting keywords for the deals and not just the leads.
  • I'm just saying that the "q string" is not the same as what keyword you bid on that matched that search. Sometimes it won't contain a single word you bid on if Google thinks the concept is close enough to something you bid on. But with only capturing the "q string", you won't be sure what keyword you bid on is performing well (or poorly). You can capture both the searched keyword and the bidded keyword by also tracking the {keyword}.
    • [2] replies
    • Hi Splinter,
      Would you mind updating us on the code you are actually using now please.
      Maybe we can all collaborate to make it more powerful and try and achieve something similar to the example 3rd party service I pointed to earlier in this thread:
      A Website Form the Retrieves Keywords & Search Engine Referrer Information

      Dan,
      Are you referring to your w3roi.com service?
      If so, it doesn't seem to be what we are trying to achieve here; i.e. have the referrer, PPC keywords and organic search terms info sent/saved with each submit of our own web forms.

      Thanks,

      - Vince
      • [1] reply
    • Dan, at the moment I bring back the entire URL in my web form submission as well as the Q string in a separate line. When I look at the Q string and the keywords in the URL that the user typed, they seem the same.

      Now are you saying that the KW query actually tells you what keyword made my advert appear on Adwords or organic listings alongside what the user actually typed in (Q String) ?


      Vince - I am using the code as show at the beginning of the thread...
  • Guys, my Google manager has left for the day and I wanted to raise a quick question. I noticed one of my staff members keeps clicking on the HTTP_Referrer link that is passed back in each lead submission we get. Now since this link sometimes contains that "gclid" id reference Google generates, would it continue to add to be analytics conversion tracking stats each time they click on this link?
  • I recently tried to implement the same solution you have in place to track keyword conversions. I got the cookie script up and is running. However I cannot seem to pass the values to the hidden fields in my form.

    What method did you use to pass the values to your form?
    • [2] replies
    • From what I can see in my programmers code is that he is storing the values in a session variable which then gets emailed to me when the form submits as well as stored in the db.

      Is this what you are doing?
    • If you are storing the values in the cookies, then all you have to do is print them in the form.

      <input type="hidden" name="keyword" value="<?php echo $_COOKIE['keyword']; ?>" />

      Replacing "keyword" with your actual field and cookie names

Next Topics on Trending Feed

  • 37

    I have asked my web designer to track the URL and Keyword for each click coming from my Adwords campaigns usin the HTTP_REFERRER variable but he seems to think that when my online form is submitted, it will only track the last URL. Can someone who has PHP experience please give me a short briefing on what I should be telling my programmer to enable him to capture the first URL when a user enters my site from a campaign so that we can assign the URL + Keyword to each form submission.