From e1fae2aa3cb33be37d67f7c0fff1fd2da7364489 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 1 May 2018 16:55:31 +0200 Subject: [PATCH 1/2] Allow extension by making members protected This allows users to extend the GoogleAnalytics class and a custom tracking code (Per user configuration for example) --- src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php b/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php index 451a528..ea264d9 100644 --- a/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php +++ b/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php @@ -22,7 +22,7 @@ class GoogleAnalytics implements AnalyticsProviderInterface * * @var string */ - private $trackingId; + protected $trackingId; /** * tracking domain From de91101ebfd170c53e099f69596041d1c634a216 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 3 May 2018 09:30:36 +0200 Subject: [PATCH 2/2] Adjusting PR Instead of making $trackingId protected, added a function which can set the $trackingId variable --- .../Contracts/AnalyticsProviderInterface.php | 9 +++++++++ .../LaravelAnalytics/Providers/GoogleAnalytics.php | 14 +++++++++++++- .../LaravelAnalytics/Providers/NoAnalytics.php | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php b/src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php index d608a59..6c1f039 100644 --- a/src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php +++ b/src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php @@ -213,6 +213,15 @@ public function ecommerceAddItem($id, $name, $sku = null, $category = null, $pri */ public function setCustom($dimension, $value = null); + /** + * set a custom tracking ID (the UA-XXXXXXXX-1 code) + * + * @param string $trackingId + * + * @return AnalyticsProviderInterface + */ + public function setTrackingId($trackingId); + /** * enables Content Security Polity and sets nonce * diff --git a/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php b/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php index ea264d9..fcad58f 100644 --- a/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php +++ b/src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php @@ -22,7 +22,7 @@ class GoogleAnalytics implements AnalyticsProviderInterface * * @var string */ - protected $trackingId; + private $trackingId; /** * tracking domain @@ -733,4 +733,16 @@ protected function _getJavascriptTemplateBlockEnd() ? '' : ''; } + + /** + * set a custom tracking ID (the UA-XXXXXXXX-1 code) + * + * @param string $trackingId + * + * @return AnalyticsProviderInterface + */ + public function setTrackingId( $trackingId ) { + $this->trackingId = $trackingId; + return $this; + } } diff --git a/src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php b/src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php index fc7461a..c7b9d0f 100644 --- a/src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php +++ b/src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php @@ -306,4 +306,15 @@ public function cspNonce() { return null; } + + /** + * set a custom tracking ID (the UA-XXXXXXXX-1 code) + * + * @param string $trackingId + * + * @return AnalyticsProviderInterface + */ + public function setTrackingId( $trackingId ) { + return $this; + } }