44
55// send an email library
66include_once dirname (__FILE__ ).'/class.phplistmailer.php ' ;
7+ require_once __DIR__ . '/analytics.php ' ;
78
89if (!function_exists ('output ' )) {
910 function output ($ text )
@@ -598,37 +599,25 @@ function sendEmail($messageid, $email, $hash, $htmlpref = 0, $rssitems = array()
598599 //# if we're not tracking clicks, we should add Google tracking here
599600 //# otherwise, we can add it when redirecting on the click
600601 if (!CLICKTRACK && !empty ($ cached [$ messageid ]['google_track ' ])) {
602+ /*
603+ * process html format email
604+ */
605+ $ analytics = getAnalyticsQuery ();
606+ $ trackingParameters = $ analytics ->trackingParameters ('HTML ' , loadMessageData ($ messageid ));
607+ $ prefix = $ analytics ->prefix ();
601608 preg_match_all ('/<a (.*)href=([" \'])(.*)\2([^>]*)>(.*)<\/a>/Umis ' , $ htmlmessage , $ links );
609+
602610 for ($ i = 0 ; $ i < count ($ links [3 ]); ++$ i ) {
603611 $ link = cleanUrl ($ links [3 ][$ i ]);
604612 $ link = str_replace ('" ' , '' , $ link );
605- //# http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55578
606-
607- $ trackingcode = 'utm_source=phplist ' .$ messageid .'&utm_medium=email&utm_content=HTML&utm_campaign= ' .urlencode ($ cached [$ messageid ]['subject ' ]);
608- //# take off existing tracking code, if found
609- if (strpos ($ link , 'utm_medium ' ) !== false ) {
610- $ link = preg_replace ('/utm_(\w+)\=[^&]+&/U ' , '' , $ link );
611- }
612- //# 16894 make sure to keep the fragment value at the end of the URL
613- if (strpos ($ link , '# ' )) {
614- list ($ tmplink , $ fragment ) = explode ('# ' , $ link );
615- $ link = $ tmplink ;
616- unset($ tmplink );
617- $ fragment = '# ' .$ fragment ;
618- } else {
619- $ fragment = '' ;
620- }
621-
622- if (strpos ($ link , '? ' )) {
623- $ newurl = $ link .'& ' .$ trackingcode .$ fragment ;
624- } else {
625- $ newurl = $ link .'? ' .$ trackingcode .$ fragment ;
626- }
627- // print $link. ' '.$newurl.' <br/>';
613+ $ newurl = addAnalyticsTracking ($ link , $ trackingParameters , $ prefix );
628614 $ newlink = sprintf ('<a %shref="%s" %s>%s</a> ' , $ links [1 ][$ i ], $ newurl , $ links [4 ][$ i ], $ links [5 ][$ i ]);
629615 $ htmlmessage = str_replace ($ links [0 ][$ i ], $ newlink , $ htmlmessage );
630616 }
631-
617+ /*
618+ * process plain-text format email
619+ */
620+ $ trackingParameters = $ analytics ->trackingParameters ('text ' , loadMessageData ($ messageid ));
632621 preg_match_all ('#(https?://[^\s\>\}\,]+)#mis ' , $ textmessage , $ links );
633622 rsort ($ links [1 ]);
634623 $ newlinks = array ();
@@ -641,28 +630,7 @@ function sendEmail($messageid, $email, $hash, $htmlpref = 0, $rssitems = array()
641630
642631 if (preg_match ('/^http|ftp/i ' , $ link )) {
643632 // && !strpos($link,$clicktrack_root)) {
644- $ url = cleanUrl ($ link , array ('PHPSESSID ' , 'uid ' ));
645- //@alpha1: maybe source should be message id?
646- $ trackingcode = 'utm_source=phplist ' .$ messageid .'&utm_medium=email&utm_content=text&utm_campaign= ' .urlencode ($ cached [$ messageid ]['subject ' ]);
647- //# take off existing tracking code, if found
648- if (strpos ($ link , 'utm_medium ' ) !== false ) {
649- $ link = preg_replace ('/utm_(\w+)\=[^&]+/ ' , '' , $ link );
650- }
651- //# 16894 make sure to keep the fragment value at the end of the URL
652- if (strpos ($ link , '# ' )) {
653- list ($ tmplink , $ fragment ) = explode ('# ' , $ link );
654- $ link = $ tmplink ;
655- unset($ tmplink );
656- $ fragment = '# ' .$ fragment ;
657- } else {
658- $ fragment = '' ;
659- }
660- if (strpos ($ link , '? ' )) {
661- $ newurl = $ link .'& ' .$ trackingcode .$ fragment ;
662- } else {
663- $ newurl = $ link .'? ' .$ trackingcode .$ fragment ;
664- }
665-
633+ $ newurl = addAnalyticsTracking ($ link , $ trackingParameters , $ prefix );
666634 $ newlinks [$ i ] = $ newurl ;
667635 $ textmessage = str_replace ($ links [1 ][$ i ], '[%%% ' .$ i .'%%%] ' , $ textmessage );
668636 }
0 commit comments