]> git.mxchange.org Git - friendica.git/commitdiff
Cleaning up tracking parameters in urls.
authorMichael Vogel <icarus@dabo.de>
Sun, 18 May 2014 18:32:06 +0000 (20:32 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 18 May 2014 18:32:06 +0000 (20:32 +0200)
include/network.php

index 310b988cb3460fcee23b4af08be4e83ae6688d8c..240d2978f1a6ea26759f8f7f2ead72d946f2e64e 100644 (file)
@@ -1107,8 +1107,29 @@ function xml2array($contents, $namespaces = true, $get_attributes=1, $priority =
 }
 
 function original_url($url, $depth=1, $fetchbody = false) {
+
+       // Remove Analytics Data from Google and other tracking platforms
+       $urldata = parse_url($url);
+       if (is_string($urldata["query"])) {
+               $query = $urldata["query"];
+               parse_str($query, $querydata);
+
+               if (is_array($querydata))
+                       foreach ($querydata AS $param=>$value)
+                               if (in_array($param, array("utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign",
+                                                       "wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid",
+                                                       "woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term"))) {
+                                       $pair = $param."=".$value;
+                                       $url = str_replace($pair, "", $url);
+                                       $url = str_replace(array("?&", "&&"), array("?", ""), $url);
+                               }
+
+               if (substr($url, -1, 1) == "?")
+                       $url = substr($url, 0, -1);
+       }
+
         if ($depth > 10)
-                return($url);
+               return($url);
 
         $url = trim($url, "'");