[mod] workaround click tracking

3rd party code for phpList

[mod] workaround click tracking

Postby Jochen » 11:15am, Tue 13 Aug, 2013

Description
This workaround enables the use of click tracking without major performance losses and with the option to track selected links only. These is achieved by a modification that only considers links with the style class attribute set to "track".

Implementation
Whenever you want to track a link just add the class attribute "track" to an "<a>" HTML tag either by editing the source or via the FCK Editor "Edit Link Advanced" tab under "Stylesheet Classes". The result is something like:

<a class="track" href="http://yourlink" target="_blank">Your Link</a>

Modification
File sendemaillib.php in folder admin

(1) Search for:
$clicktrack_root = sprintf('%s://%s/lt.php',$GLOBALS["scheme"],$website.$GLOBALS["pageroot"]);

Should be around line 484.

(2) Add the following lines after "$link = cleanUrl($links[2][$i]);"

Code: Select all
if ( (strcmp(strtolower(trim($links[1][$i])), 'class="track"') == 0)  || (strcmp(strtolower(trim($links[3][$i])), 'class="track"') == 0) ) {
               print ($i+1) . ". tracked link: ". $link."<br/>";


(3) Add the bracket "}" after "$htmlmessage = str_replace($links[0][$i], $newlink, $htmlmessage);"

Complete coding for this condition:

Code: Select all
// consider only links with the class attribute "track"
if ( (strcmp(strtolower(trim($links[1][$i])), 'class="track"') == 0)  || (strcmp(strtolower(trim($links[3][$i])), 'class="track"') == 0) ) {
   // print tracked links to screen
   print ($i+1) . ". tracked link: ". $link."<br/>";
      
   $link = str_replace('"','',$link);
   if (preg_match('/\.$/',$link)) {
      $link = substr($link,0,-1);
   }
   // print "LINK: ". $link."<br/>";
   $linkid = 0;
   #     print "LINK: ".htmlspecialchars($link)."<br/>";
   if ((preg_match('/^http|ftp/',$link) || preg_match('/^http|ftp/',$urlbase)) && $link != 'http://www.phplist.com' && !strpos($link,$clicktrack_root)) {
      # take off personal uids
      $url = cleanUrl($link,array('PHPSESSID','uid'));

   #        $url = preg_replace('/&uid=[^\s&]+/','',$link);

   #        if (!strpos('http:',$link)) {
   #          $link = $urlbase . $link;
   #        }

      $req = Sql_Query(sprintf('insert ignore into %s (messageid,userid,url,forward)
        values(%d,%d,"%s","%s")',$GLOBALS['tables']['linktrack'],$messageid,$userdata['id'],$url,addslashes($link)));
      $req = Sql_Fetch_Row_Query(sprintf('select linkid from %s where messageid = %s and userid = %d and forward = "%s"
      ',$GLOBALS['tables']['linktrack'],$messageid,$userdata['id'],$link));
      $linkid = $req[0];

      $masked = "H|$linkid|$messageid|".$userdata['id'] ^ XORmask;
      $masked = urlencode(base64_encode($masked));
      
      $newlink = sprintf('<a%shref="%s://%slt.php?id=%s" %s>%s</a>',$links[1][$i],$GLOBALS["scheme"],$website.$GLOBALS["pageroot"],$masked,$links[3][$i],$links[4][$i]);
      $htmlmessage = str_replace($links[0][$i], $newlink, $htmlmessage);
   }
}


(4) Don't forget to to set the following config.php settings:

define('CLICKTRACK',1);
define('CLICKTRACK_SHOWDETAIL', 1);

Any feedback is very much appreciated.
Jochen
phpLister
 
Posts: 7
Joined: 10:53am, Mon 12 Aug, 2013

Return to Contributions: Plug-ins, Add-ons, Mods

Who is online

Users browsing this forum: No registered users and 2 guests