From 5c58eb8e2fe8f6d6f55579043e3a0f9ff8907b62 Mon Sep 17 00:00:00 2001 From: Michael Khalili Date: Fri, 11 Sep 2015 04:37:37 -0400 Subject: [PATCH] http_build_query incorrectly encodes spaces The http_build_query will encode a space as a plus sign. This should be encoded as %20, instead of "+". Encoding as a + will cause Google Analytics to display it as a plus sign. By manually building the query string, we can use rawurlencode to do proper encoding of spaces. --- ss-ga.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ss-ga.class.php b/ss-ga.class.php index 8633e93..f461919 100644 --- a/ss-ga.class.php +++ b/ss-ga.class.php @@ -64,13 +64,13 @@ public function __construct( $UA = null, $domain = null ) { * @return string */ public function create_gif() { - $data = array(); + $query = ''; foreach ( $this->data as $key => $item ) { if ( $item !== null ) { - $data[$key] = $item; + $query .= rawurlencode($key) . "=" . rawurlencode($item) . '&'; } } - return $this->tracking = self::GA_URL . '?' . http_build_query( $data ); + return $this->tracking = self::GA_URL . '?' . $query; } /**