Foro de usuarios de phpTrafficA
 
Página principal de phpTrafficA
 
Por favor, ¡haz tus preguntas en inglés o francés!. La ayuda en otros lenguajes puede ser lenta.
Russian speaking users can find Russian discussions on phpTrafficA at ru-board.com
 
Operaciones:  Lista de temas Lista de temas  Nuevo tema Nuevo tema  Responder en este tema Responder en este tema
Buscar 
Búsqueda avanzada
Tema "[FR] Selective "Trim URL" function" Comenzado por Mauro el: 16/09/2008 1:15
Página actual: 1 de 1 Ir a página: 1
[FR] Selective "Trim URL" function
Enviado por: Mauro  el: 16/09/2008 1:15
Hi there butchu. Been playing with TrafficA and right after the first few hours I decided to drop the two trackers I was already using (extreme tracking and google analytics) in favour of it.
What is useful at 50% in my opinion is the Trim URL option.
Practical example: right after TrafficA installation, I had no page.php?parameters pages, then I modified one so it is like docs.php?doc=doctitle, and Trim URL to off was the obvious subsequent step.
But now that I'm going to launch freeforum, that function will fire back, since if on one side I need to track the docs.php?doc=doctile parameter, I don't want to have separate hits for each forum.php?mode=blahblah page.
A useful addition would be to choose which pages to use Trim URL on (trim URL on forum.php, but don't trim URL on docs.php), and optionally (even if that would be useful as well) choose WHICH parameters to strip off each dynamic page (for example, if I have a userfeedback.php?title=titlename&view=bigchars, I may want to NOT trim URL, but then it would be useful to ignore the view=* parameter and only count as single page the title=* parameter).
Ad
Re: [FR] Selective "Trim URL" function
Enviado por: Butchu  el: 16/09/2008 8:15
You have to customize the write_logs.php function. Here is a function that will trim selected parameters out of a url:
///////////////////////////////////////////////////////
// Function: query_string
// Description: Format the Query_String (removes the arguments
// used by FreeForum, and leave the others)
////////////////////////////////////////////////////////
function query_string($q_string, $strips) {
foreach($strips as $key) {
$strips[$key] = TRUE;
}
$q_string = str_replace("&","&", $q_string);
$var_value = explode("&", $q_string);
foreach($var_value as $var_peace){
$parts = explode("=", $var_peace);
if($strips[$parts[0]] != TRUE and $parts[0] != "") {
$my_q .= "$var_peace&";
}
}
//if( substr($my_q, -5) == "&" ){ $my_q = substr($my_q, 0, -5); }
return $my_q;
}

If you want to ignore the view and title paramaters, you use it this way

$query = query_string($_SERVER["QUERY_STRING"], array("view", "title));
$thispage = $_SERVER["PHP_SELF"]."?$query";

In write_logs.php play with lines 58-63.

If you're using the image counter, you will have to play with the file count.php.
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 16/09/2008 9:13
I can't really argue with that! ;) I just have to tamper with the code as suggested, thanks for the ultrarapid fix!
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 16/09/2008 18:35
I tested and played a bit with your snippet code, and the line you commented out,
//if( substr($my_q, -5) == "&" ){ $my_q = substr($my_q, 0, -5); }

was actually useful as
if( substr($my_q, -1) == "&" ){ $my_q = substr($my_q, 0, -1); }

and the ending more like

$thispage=$_SERVER["PHP_SELF"]; if ($query) {$thispage = $thispage."?$query";}


In my case anyway, in the end, I only had to modify line 59 of write_logs.php as

if (($phpTA_sites[$sid]['trim']) || strpos($_SERVER["PHP_SELF"],"forum.php")) {

What I think would be a cool addition (I think elementary to implement, as it's user-interface only, even if I'd be too noob to do this myself) would be the ability to define a base option for Trim URL as it it now, and a separate form where to insert overrides (something like how you can add yourself definitions for browsers, OSes and search engines).
Example: Trim URL to on, but in override forms you define:

docs.php (tracks all query params)
forum.php|viewtopic,viewforum (tracks only viewtopic and viewforum params)
Re: [FR] Selective "Trim URL" function
Enviado por: Butchu  el: 18/09/2008 8:08
I'll add this in the todo list, but for future versions. I want to release 2.1 soon!
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 18/09/2008 17:02
I totally understand, from what I could guess from the new strings to translate, 2.1 is cool like it is, nonetheless ;)

In the meantime, this is a modified version of your suggested query_string() function, which instead of removing selected query parameters, actually selects ONLY the set parameters (for example "viewtopic" in forums, "gallery" in galleries, and so on) ignoring all other params being passed, whatever they may be.

// Function: query_string
// Description: keeps only query string parameters selected by user
// and ignores the others

function query_string($q_string, $usefulkeys) {
foreach($usefulkeys as $key) {
$usefulkeys[$key] = TRUE;
}
//this is what I think you wanted to do, instead of just replacing "&" by "&" ;)
$q_string = str_replace("&","&", $q_string);

$var_value = explode("&", $q_string);
foreach($var_value as $var_piece){
$parts = explode("=", $var_piece);
if(($usefulkeys[$parts[0]] == TRUE) && ($parts[0] != "")) {
$my_q .= "$var_peace&";
}
}
if( substr($my_q, -1) == "&" ){ $my_q = substr($my_q, 0, -1); }
return $my_q;
}


and hence

$query = query_string($_SERVER["QUERY_STRING"], array("viewtopic", "gallery","doc","whateveryouneedtotrack"));
$thispage=$_SERVER["PHP_SELF"]; if ($query) {$thispage = $thispage."?$query";}
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 18/09/2008 17:03
By the way, why the CODE tag doesn't work with multiple lines?
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 18/09/2008 17:21
...consequences of missing edit feature (only obvious since there's no login, freeForum is cool as it is ;))

there's a typo in the code I pasted, a $var_peace slipped, they should all read $var_piece
Re: [FR] Selective "Trim URL" function
Enviado por: Mauro Savone  el: 18/09/2008 17:23
GEE, I also meant

$q_string = str_replace("&","&", $q_string);

Sorry for the flood :)
Re: [FR] Selective "Trim URL" function
Enviado por: Butchu  el: 19/09/2008 9:06
Mauro Savone :
Sorry for the flood :)

No problem, this thread will be useful for implementing the feature later on.
I get you a coffee!
Enviado por: Butchu  el: 19/05/2013 2:08
Gee, I really liked this answer! I want to thank you and I buy you a coffee!
Página actual: 1 de 1 Ir a página: 1
Forum powered by FreeForum
© 2004-2010 ZoneO-soft - Spanish translation by Samuel Aguilera, www.samuelaguilera.com
phpTrafficA homepage in: English - Français - Русский - Deutsch - Español - Nederlands - Romaneste - Svenska - Italiano
Also available at ZoneO: freeForum -- phpTrafficA -- Linux-tips -- Unixtime Online -- PageRank online
Page generation: 0.137 sec