Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

Commit 38511d0

Browse files
author
Robert Kummer
committed
adding displayfeatures plugin for google analytics
1 parent b3356e4 commit 38511d0

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class GoogleAnalytics implements AnalyticsProviderInterface
2828
*/
2929
private $trackingDomain;
3030

31+
/**
32+
* display features plugin enabled or disabled
33+
*
34+
* @var bool
35+
*/
36+
private $displayFeatures = false;
37+
3138
/**
3239
* anonymize users ip
3340
*
@@ -81,6 +88,7 @@ public function __construct(array $options = array())
8188
{
8289
$this->trackingId = array_get($options, 'tracking_id');
8390
$this->trackingDomain = array_get($options, 'tracking_domain', 'auto');
91+
$this->displayFeatures = array_get($options, 'display_features', false);
8492
$this->anonymizeIp = array_get($options, 'anonymize_ip', false);
8593
$this->autoTrack = array_get($options, 'auto_track', false);
8694
$this->debug = array_get($options, 'debug', false);
@@ -159,24 +167,52 @@ public function trackCustom($customCode)
159167
$this->trackingBag->add($customCode);
160168
}
161169

170+
/**
171+
* enable display features
172+
*
173+
* @return GoogleAnalytics
174+
*/
175+
public function enableDisplayFeatures()
176+
{
177+
$this->displayFeatures = true;
178+
179+
return $this;
180+
}
181+
182+
/**
183+
* disable auto tracking
184+
*
185+
* @return GoogleAnalytics
186+
*/
187+
public function disableDisplayFeatures()
188+
{
189+
$this->displayFeatures = false;
190+
191+
return $this;
192+
}
193+
162194
/**
163195
* enable auto tracking
164196
*
165-
* @return void
197+
* @return GoogleAnalytics
166198
*/
167199
public function enableAutoTracking()
168200
{
169201
$this->autoTrack = true;
202+
203+
return $this;
170204
}
171205

172206
/**
173207
* disable auto tracking
174208
*
175-
* @return void
209+
* @return GoogleAnalytics
176210
*/
177211
public function disableAutoTracking()
178212
{
179213
$this->autoTrack = false;
214+
215+
return $this;
180216
}
181217

182218
/**
@@ -194,6 +230,10 @@ public function render()
194230
$script[] = "ga('create', '{$this->trackingId}', '{$this->trackingDomain}');";
195231
}
196232

233+
if ($this->displayFeatures) {
234+
$script[] = "ga('require', 'displayfeatures');";
235+
}
236+
197237
if ($this->anonymizeIp) {
198238
$script[] = "ga('set', 'anonymizeIp', true);";
199239
}

src/config/analytics.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* The Google Analytics provider supports the following properties:
1717
* - tracking_id (string)
1818
* - tracking_domain (string:auto) - default will be 'auto' if config property not exists
19+
* - display_features (bool) - default will be false if no config property exists
1920
* - anonymize_ip (bool) - default will be false if no config property exists
2021
* - auto_track (bool) - default will be false if no config property exists
2122
* - debug (bool) - default will be false if no config property exists
@@ -32,6 +33,11 @@
3233
*/
3334
'tracking_domain' => 'auto',
3435

36+
/**
37+
* enabling the display feature plugin
38+
*/
39+
'display_features' => false,
40+
3541
/**
3642
* Use ip anonymized
3743
*/

0 commit comments

Comments
 (0)