From: Michael Vogel Date: Sun, 18 May 2014 18:32:06 +0000 (+0200) Subject: Cleaning up tracking parameters in urls. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6b461a74cb0c9995c4a702fb051558547f9ee531;p=friendica.git Cleaning up tracking parameters in urls. --- diff --git a/include/network.php b/include/network.php index 310b988cb3..240d2978f1 100644 --- a/include/network.php +++ b/include/network.php @@ -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, "'");