Jump to content
Sign in to follow this  
Guest

User tracking Contribution; doesn't save the originating URL

Recommended Posts

Guest

I'm just curious why the user contribution does not save the originating URL field. It seems that once the session expires, that field is blank when it originally had something in there when I checked earlier. This is one of my main criteria I need to track, and this contrib is a great way to find the customers that have purchased, and where they came from. Isn't the contrib getting this from my raw log files? Or is it being stored in the session, and disappearing when it expires?

Share this post


Link to post
Share on other sites

Sorry I don't have a solid answer for you, but this is the 3rd time I've seen a reference to a "user tracking" contrib, but I can't find it anywhere. Could you point me to it so I can check it out?

 

More than likely it is expiring when the session dies. I won't say it's not reading your raw log files, but that would be a piece of work and unless you set it up to tell it where to find your logs and the format, it's more than likely working off of a simple $HTTP_REFERER check. If the browser/bot/program hitting your site has privacy enabled, it won't show where they came from.

 

The ones that do show a referring URL and do make purchases should be able have that URL logged into the database with the order with little effort though...

Share this post


Link to post
Share on other sites

Mattice--

Thanks for the link...I looked through the contrib section about 20x...never thought to look in the forums :)

 

tyler--

Yep, after a quick peek, it works off an $HTTP_REFERER check:

$referer_url = $HTTP_SERVER_VARS['HTTP_REFERER'];

As I said, not all user agents will report this when entering your site, so don't count on seeing referers for every user...

Share this post


Link to post
Share on other sites

Y'r welcome Ross.. I've often wondered why he never uploaded it to the osC main site.

 

You should check for the X_FORWARDED_FOR (or something like that, don't recall exactly) too so it tries to look beyond any proxy.


"Politics is the art of preventing people from taking part in affairs which properly concern them"

Share this post


Link to post
Share on other sites

Yeah, that's correct, $_ENV['HTTP_X_FORWARDED_FOR']. Don't worry, I'll spruce it up if I like it...always do ;)

Share this post


Link to post
Share on other sites
Yeah, that's correct, $_ENV['HTTP_X_FORWARDED_FOR'].  Don't worry, I'll spruce it up if I like it...always do ;)

 

Have no fear... Ross is here! :D

 

I still need to install this on a live site and check it out so I actually have never seen it in action. Heard good things about it though...

I guess a little check will be all that is needed... if there is XFWD use that, if not check for REFERER and if that doesn't cough it up.... foobarred.


"Politics is the art of preventing people from taking part in affairs which properly concern them"

Share this post


Link to post
Share on other sites

I haven't installed this script yet either, but on a banning script I added to my Admin login script (3 strikes and you're out), I used this to log their info with the ban:

 

if ($_ENV('HTTP_X_FORWARDED_FOR')) { 

      $ip = $_ENV('HTTP_X_FORWARD_FOR'); 

      $host = $_SERVER['REMOTE_HOST']; 

  } else { 

      $ip = $_SERVER['REMOTE_ADDR']); 

      $host = $_SERVER['REMOTE_HOST']; 

  }

 

Just define the REFERRER global inside the conditions and you'll be set...it works great...

Share this post


Link to post
Share on other sites

if ($_ENV('HTTP_X_FORWARDED_FOR')) { 

      $ip = $_ENV('HTTP_X_FORWARD_FOR');

 

shouldn't that be

 

if ($_ENV('HTTP_X_FORWARDED_FOR')) { 

      $ip = $_ENV('HTTP_X_FORWARDED_FOR');

 

Thnx ;)


"Politics is the art of preventing people from taking part in affairs which properly concern them"

Share this post


Link to post
Share on other sites

LOL, guess I should just open the file and copy/paste rather than typing it. As always, my code contains no warranty...use it at your own risk...typos and all ;)

Share this post


Link to post
Share on other sites

Wow, I guess we both missed it :D

 

if ($_ENV('HTTP_X_FORWARDED_FOR')) { // this is not a function

      $ip = $_ENV('HTTP_X_FORWARDED_FOR'); 

      $host = $_SERVER['REMOTE_HOST']; 

  } else { 

      $ip = $_SERVER['REMOTE_ADDR']); // extra )

      $host = $_SERVER['REMOTE_HOST']; 

  }

 

Should be:

if ($_ENV['HTTP_X_FORWARDED_FOR']) {   // fixed [ ]

      $ip = $_ENV['HTTP_X_FORWARDED_FOR']; 

      $host = $_SERVER['REMOTE_HOST']; 

  } else { 

      $ip = $_SERVER['REMOTE_ADDR'];  // fixed )

      $host = $_SERVER['REMOTE_HOST']; 

  }

 

Additionally, regarding the user_tracking contrib, it looks pretty cool. One thing I noticed is that even though the SIDs are logged and listed as the main heading for each user, the SIDs are still appended to URLs in each section. Since the URLs are active links and have the SIDs, you could click the link of someone in your store to see where they're at and accidentally share their session. Not a biggie I guess, but not really "right" either.

 

Maybe more at issue is the fact that if the user leaves the window open for more than 20-25 min. idle and then starts browsing again, logging does not work. I'll assume that this is directly related to the session being deleted from the DB (when store sessions = mysql in my case).

 

This might not be a big deal unless your store includes content to sit and read instead of just products to browse. For some reason, I always thought that OSC re-inserted a session into the DB if it timed out and was brought back to life?

Share this post


Link to post
Share on other sites
Guest

The real problem I was talking about here is not recording the URL (I understanhd many times it's blocked), but after an hour or so, the originating URL disappears. If I don't check the URL tracking for a few hours, I can miss the originating URL. Case in point. I woke up this morning and saw in an originating URL that some found my site through Lycos, with a certain search term. 2 hours later when I got to work and looked at that page again, that session is still in my admin tracking, BUT there is no originating URL anymore. Is there a way I can put this into the user_tracking table to have it stored so I can compare the originating url to user/purchase tracking?

Share this post


Link to post
Share on other sites

Yes, the referer is simply registered as session variable in application_top, so when the session is destroyed, so is the variable. I just added a "came_from" field (and user_agent) to the user_tracking table so they will be stored permanently and added this to the catalog function (for PHP 4.1.0+):

 

$if (isset($_SESSION['referer_url'])){

$referer = $_SESSION['referer_url'];

}

 

Then add the appropriate changes to the insert query (came_from = $referer) and then change the appropriate code in the admin page to call and display the new field. I haven't even tried it out yet, but it *should* work... ;)

Share this post


Link to post
Share on other sites
Guest

Alright,

sorry to be bugging you so much, but php is not my area of expertise, and am kind of lost with this. I can add the table for CAME_FROM, but i'm not sure what to do after that. Anyway you could maybe cut and paste the code you changed, and post it here. I'd be greatly appreciative of it...

Share this post


Link to post
Share on other sites

First, CAME_FROM is a field to be added to the user_tracking table, not a separate table itself. I made mine VARCHAR and length = 100 I think.

 

I made a bunch of little changes here and there. Caveat: these are *quick* changes and have not been tested on a production server or with more than one user (me) online at the same time. Also, this will only work on PHP 4.1.0+ because I used superglobal arrays in the function.

 

In catalog/application_top.php, after "tep_session_start();" I removed:

 

// user_tracking modications

 if (!$referer_url) {

   $referer_url = $HTTP_SERVER_VARS['HTTP_REFERER'];

   tep_session_register('referer_url');

 }

 

catalog/includes/functions/user_tracking.php (whole file):

<?php

/*

 $Id$

 osCommerce, Open Source E-Commerce Solutions

 http://www.oscommerce.com



 Copyright (c) 2002 osCommerce



 Released under the GNU General Public License



 Modified by Ross Lapkoff (rlapkoff@austin.rr.com)

 12/13/2002

*/





 function tep_update_user_tracking() {



if (!isset($_SESSION['referer'])){

  if ($_SERVER['HTTP_REFERER'] != '') {

 $_SESSION['referer'] = $_SERVER['HTTP_REFERER'];

 } else {

 $_SESSION['referer'] = 'None or Privacy Enabled';

 }

}

   $customer_id = $_SESSION['customer_id'];



   $skip_tracking['64.91.104.73'] = 1; // useless without a static IP -- RSL



   if (isset($customer_id)) 

   {

     $wo_customer_id = $customer_id;



     $customer_query = tep_db_query("select customers_firstname, customers_lastname from " . TABLE_CUSTOMERS . " where customers_id = '" . $customer_id . "'");

     $customer = tep_db_fetch_array($customer_query);



     $wo_full_name = addslashes($customer['customers_firstname'] . ' ' . $customer['customers_lastname']);

   } 

   else 

   {

     $wo_customer_id = '';

     $wo_full_name = 'Guest';

   }

   

   $wo_session_id = tep_session_id();

	 

 if ($_SERVER['HTTP_X_FORWARDED_FOR']) { 

     $wo_ip_address   = $_SERVER['HTTP_X_FORWARDED_FOR']; 

   } else { 

     $wo_ip_address   = $_SERVER['REMOTE_ADDR']; 

   }

 

   $wo_last_page_url = addslashes($_SERVER['REQUEST_URI']);

   

 if (isset($_SESSION['referer'])){

   $referer = $_SESSION['referer'];

 }



   $current_time = time();

   if ($skip_tracking[$wo_ip_address] != 1)

     tep_db_query("insert into " . TABLE_USER_TRACKING . " (customer_id, full_name, session_id, ip_address, came_from, time_entry, time_last_click, last_page_url) values ('" . $wo_customer_id . "', '" . $wo_full_name . "', '" . $wo_session_id . "', '" . $wo_ip_address . "', '" . $referer . "', '" . $current_time . "', '" . $current_time . "', '" . $wo_last_page_url . "')");

 }

?>

 

admin/user_tracking.php, change the query to include your new came_from field (around line 88 ):

  // we need to slurp all the customer tracking information out of the database

 $whos_online_query = 

     tep_db_query("select customer_id, full_name, ip_address, came_from, time_entry, time_last_click, last_page_url," .

 

and a few lines under that, define the variable for the referer with the rest of them:

$user_tracking[$whos_online['session_id']]['came_from']=$whos_online['came_from'];

 

Then around line 217 where the dispay tables are, find the current echo referer and replace it with the new variable:

 

<!-- Replace this 

<td class="dataTableContent2" align="right" valign="top"><?php echo TEXT_ORIGINATING_URL ?></td>

<td class="dataTableContent" align="left" valign="top"><?php echo chunk_split($referer_url,40,"<br>"); ?></td>

-->

<!-- With this -->

<td class="dataTableContent" align="right" valign="top"><u><?php echo TEXT_ORIGINATING_URL ?></u></td>

<td class="dataTableContent" align="left" valign="top"><?php echo $ut['value']['came_from']; ?></td>

 

That's a lot of copy/paste, so hopefully there are no errors....let me know if you have any problems....

Share this post


Link to post
Share on other sites
Guest

Thanks so much!! this rocks! It looks like it's working pretty good!

Share this post


Link to post
Share on other sites
Guest

Ross Help!!

 

I get this error when I go to My Account page after adding those lines...

 

Warning: Cannot add header information - headers already sent by (output started at /home/illuminous-times.com/httpdocs/includes/functions/user_tracking.php:62) in /home/illuminous-times.com/httpdocs/includes/functions/general.php on line 23

 

Damn, I think I just lost a sale from it...

Share this post


Link to post
Share on other sites
Guest

Well I changed it back for the moment, but it bites to learn it wasn't working by losing a sale. I should of tested it more. It looks like it was getting that message going to a SSL page. I have a test site to work on these now...

Share this post


Link to post
Share on other sites

Sorry, I never got email notices from your posts. More than likely, you had an extra space after the closing ?> tag on that page. Line 62 would be close to last line, so that's what I think probably happened.

 

Make sure there are no blank lines or spaces after the closing ?> at all and no echo or print statements anywhere in that function. Anything that tries to print something to the screen (even just a space outside of the php tags), will cause those header output errors.

Share this post


Link to post
Share on other sites

:D Hi! I've been following this thread and thought I'd give this thing a whirl. I'm a php and osCommerce newbie but the ad tracking thing was something I really needed.

 

I wrote a simple modification to record ad tracking and referer data when users register for the first time.

 

Let me know what you think. Suggestions and improvements are welcome.

 

http://www.oscommerce.com/downloads.php/co...ions,804/type,3


Adam

--------------------------------

got monkey? We do.

http://www.monkeygoods.com

Share this post


Link to post
Share on other sites
Guest

Ok, I got everything working now. But i'm getting this error when I try to purge the data past the 24 hour period.

 

 

Warning: Address is not in a.b.c.d form in /home/illuminous-times.com/httpdocs/admin/user_tracking.php on line 205

 

 

any clues?

Share this post


Link to post
Share on other sites

Hi,

I installed this mod, but I'm getting each time I move to a page on my test server, it creates a new record, with the previous page as the originating URL. Any ideas what's going on here?

 

Thanks

 

 

In catalog/application_top.php, after "tep_session_start();" I removed:

 

// user_tracking modications

 if (!$referer_url) {

   $referer_url = $HTTP_SERVER_VARS['HTTP_REFERER'];

   tep_session_register('referer_url');

 }

Share this post


Link to post
Share on other sites

I'm having the same prob - all i wanna do is store the originating URL string in the database - can someone help?

 

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×