[FIXED] a problem about trackGoal and trackLink


(cn_Dark) #1

Hello,

I find a collison for the parameters send by method get and post.

In js tacking code, trackGoal and trackLink and use “data=” for parameters customVars, I use “Piwik_Common::getRequestVar(‘data’)” to get data of customVars.

The problem is : when I open piwik/index.php, there is also a POST data which have the same parameters “data”. So, when I view piwik/index.php, it track and write this data into database. (Because I modify tracker/visit.php to save the data send by trackLink and trackGoal, I don’t find how to write a plugin to write the data send by trackLink and trackGoal. ) I think that it is better to change the name of parameters “data=” for trackLink and trackGoal. style_emoticons/<#EMO_DIR#>/smile.gif


(vipsoft) #2

There shouldn’t be any conflict. First, the tracker encodes the URL. Second, the tracker calls piwik.php (not index.php) in a separate request.

Maybe you could post your “diff” of core/Tracker/Visit.php, so that we can figure out what’s wrong with your hack.


(cn_Dark) #3

[quote=vipsoft @ Jul 22 2009, 02:21 PM]There shouldn’t be any conflict. First, the tracker encodes the URL. Second, the tracker calls piwik.php (not index.php) in a separate request.

Maybe you could post your “diff” of core/Tracker/Visit.php, so that we can figure out what’s wrong with your hack.[/quote]
But when I view index.php, piwik always log the data in piwik_log_visit.
This is my code, I add 2 function in the class Piwik_Tracker_Visit.

class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface {
          .......
          .......
    /**
     * ECommerce Code
     */
    function getECommerceVars($data,$key,$default = 'NULL') {
        return (isset($data[$key]) && $data[$key] !== '') ? "'".$data[$key]."'" : $default; 
    }

    /**
     * ECommerce code
     */
    function logECommerceData($idvisit) {

        //receive data of e_commerce
        $rData = Piwik_Common::getRequestVar('data',NULL);

        //check whther there is data of e_commerce, if no data, return
        if (empty($rData)) return;
        
        $rData = html_entity_decode($rData);        
        $data = json_decode( $rData, true );
        
        //if Piwik_Common::getRequestVar('eCommerce',NULL) is null, it is 
        //said this data is not send by trackLink, so we need ignore these datas
        if (Piwik_Common::getRequestVar('eCommerce',NULL) === NULL) return;
        
        $reference_commande=
        $this->getECommerceVars($data,'reference_commande');
        $montant_total_TTC_commande = 
               $this->getECommerceVars($data,'montant_total_TTC_commande');
        $montant_total_taxes_commande =                 
                $this->getECommerceVars($data,'montant_total_taxes_commande');
        $montant_total_frais_port_commande = 
        $this->getECommerceVars($data,'montant_total_frais_port_commande');
        $email_client = $this->getECommerceVars($data,'email_client');
        $idclient = $this->getECommerceVars($data,'idclient');
        $ville_livraison_commande =  
                $this->getECommerceVars($data,'ville_livraison_commande');
        $pays_livraison_commande = 
                $this->getECommerceVars($data,'pays_livraison_commande');
        $region_livraison_commande = 
                $this->getECommerceVars($data,'region_livraison_commande');
        $apporteur_ayany_permis = 
               $this->getECommerceVars($data,'apporteur_ayany_permis');
        $mot_clef_ayant_permis = 
               $this->getECommerceVars($data,'mot_clef_ayant_permis');
        $reference_article = 
                $this->getECommerceVars($data,'reference_article');
        $nom_article = $this->getECommerceVars($data,'nom_article');
        $gamme_article = $this->getECommerceVars($data,'gamme_article');
        $prix_article = $this->getECommerceVars($data,'prix_article');
        $nombre_article = $this->getECommerceVars($data,'nombre_article');

        $idsite = Piwik_Common::getRequestVar('idsite');
        $server_time = "'".date('Y-m-d G:i:s',time())."'";

        //insert values into tables_prefix_log_ecommerce, make query firet
        $query = "INSERT INTO ".Piwik_Common::prefixTable('log_ecommerce').
               "(idsite,
               idvisit,
               server_time,
               reference_commande,
               montant_total_TTC_commande,
               montant_total_taxes_commande,
               montant_total_frais_port_commande,
               email_client,
               idclient,
               ville_livraison_commande,
               pays_livraison_commande,
               region_livraison_commande,
               apporteur_ayany_permis,
               mot_clef_ayant_permis,
               reference_article,
               nom_article,
               gamme_article,
               prix_article,
               nombre_article) 
               VALUES
               ($idsite,
               $idvisit,
               $server_time,
               $reference_commande,
               $montant_total_TTC_commande,
               $montant_total_taxes_commande,
               $montant_total_frais_port_commande,
               $email_client,
               $idclient,
               $ville_livraison_commande,
               $pays_livraison_commande,
               $region_livraison_commande,
               $apporteur_ayany_permis,
               $mot_clef_ayant_permis,
               $reference_article,
               $nom_article,
               $gamme_article,
               $prix_article,
               $nombre_article)";
               
        //run the query
        Piwik_Tracker::getDatabase()->query($query);        
    }
}

And I add the code in to run getECommerceVars in function $this->handle:

class Piwik_Tracker_Visit implements Piwik_Tracker_Visit_Interface {
    .....
    ......
    public function handle() {
          ......
          .......
          //ECommerce Code
    $this->logECommerceData($this->visitorInfo['idvisit']);
        //End of ECommerce Code

        // update the cookie with the new visit information
        $this->updateCookie();

        // record the goals if applicable
        if($someGoalsConverted) 
        {
            $goalManager->setCookie($this->cookie);
            $goalManager->recordGoals($this->visitorInfo, $action);
        }
        unset($goalManager);
        unset($action);
  }
.....
......
}

(cn_Dark) #4

I dont study index.php of piwik, it seems that when I open index.php, it will visit the site we want track ?
I can see in piwik_log_visit, if I open index.php in my browser, it will be log in piwik_log_visit and the reffer_url is " http://localhost/piwik/index.php?module=Co…ate=today"
BTW, I installed plugin “GEOIP”.

Sorry for my English style_emoticons/<#EMO_DIR#>/sad.gif


(vipsoft) #5

No. What you’re seeing is the piwik.org tracking code. I’ve now tweaked this in svn. See:

http://dev.piwik.org/trac/changeset/1322


(cn_Dark) #6

[quote=vipsoft @ Jul 23 2009, 01:46 PM]No. What you’re seeing is the piwik.org tracking code. I’ve now tweaked this in svn. See:

http://dev.piwik.org/trac/changeset/1322[/quote]
Thanks