Forum Moderators: DixonJones

Message Too Old, No Replies

Tracking search engine referrals

Tracking search engine referrals

         

morty

6:54 pm on Dec 18, 2004 (gmt 0)

10+ Year Member



How hard (or possible) is it to add the search query to an account so that I know how someone came to my site?

In other words, if a user got to my site searching on "Blue Widgets" in Google, I'd like to add this to his account record so I know the source of this visit.

Is this possible for organic and paid search?

Chico_Loco

2:33 pm on Dec 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, PERL is your friend..

Have you got SSI enabled on your html pages? Great (if not read up on it).

1. Create a file called trackster.pl in your CGI bin.

Code for trackster.pl:

#!/usr/bin/perl

$from=$ENV{'HTTP_REFERER'};

if ($from =~ "google")
{
$from =~ s/.*q=//;
$from =~ s/&.*//;
$from =~ s/\+/ /g;
open(FILE,">>./google-people.txt");
print FILE "$ENV{'REMOTE_ADDR'} Searched Google For: $from\n";
close(FILE);
}
exit;

# END CODE
----------

2. CHMOD trackster.pl to 755.
3. create a file called google-people.txt in the same directory as the .pl file - CHMOD it to 777
4. Add this line to your SSI enabled pages: <!--#exec cgi="/cgi-bin/trackster.pl" -->

The file google-people.txt will show you what people searched for on Google. If logged in via SSH/telnet you can look at it in real time with "tail -f google-people.txt"

This is of course just a simple example, but this would work.