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

Commit 8c4761a

Browse files
author
Robert Kummer
authored
Merge pull request #54 from CryptoSmileee/master
Add google optimize
2 parents 0563d99 + a7dfe61 commit 8c4761a

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/Ipunkt/LaravelAnalytics/Contracts/AnalyticsProviderInterface.php

+9
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,15 @@ public function setCustom($dimension, $value = null);
222222
*/
223223
public function setTrackingId($trackingId);
224224

225+
/**
226+
* set a custom optimize ID (the GTM-XXXXXX code)
227+
*
228+
* @param string $optimizeId
229+
*
230+
* @return AnalyticsProviderInterface
231+
*/
232+
public function setOptimizeId($optimizeId);
233+
225234
/**
226235
* enables Content Security Polity and sets nonce
227236
*

src/Ipunkt/LaravelAnalytics/Providers/GoogleAnalytics.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class GoogleAnalytics implements AnalyticsProviderInterface
2424
*/
2525
private $trackingId;
2626

27+
/**
28+
* optimize id
29+
*
30+
* @var string
31+
*/
32+
private $optimizeId;
33+
2734
/**
2835
* tracking domain
2936
*
@@ -132,6 +139,7 @@ class GoogleAnalytics implements AnalyticsProviderInterface
132139
public function __construct(array $options = [])
133140
{
134141
$this->trackingId = array_get($options, 'tracking_id');
142+
$this->optimizeId = array_get($options, 'optimize_id');
135143
$this->trackingDomain = array_get($options, 'tracking_domain', 'auto');
136144
$this->trackerName = array_get($options, 'tracker_name', 't0');
137145
$this->displayFeatures = array_get($options, 'display_features', false);
@@ -449,6 +457,10 @@ public function render()
449457
$script[] = "ga('require', 'displayfeatures');";
450458
}
451459

460+
if ($this->optimizeId) {
461+
$script[] = "ga('require', '{$this->optimizeId}');";
462+
}
463+
452464
if ($this->anonymizeIp) {
453465
$script[] = "ga('set', 'anonymizeIp', true);";
454466
}
@@ -744,5 +756,17 @@ protected function _getJavascriptTemplateBlockEnd()
744756
public function setTrackingId( $trackingId ) {
745757
$this->trackingId = $trackingId;
746758
return $this;
747-
}
759+
}
760+
761+
/**
762+
* set a custom optimize ID (the GTM-XXXXXX code)
763+
*
764+
* @param string $optimizeId
765+
*
766+
* @return AnalyticsProviderInterface
767+
*/
768+
public function setOptimizeId( $optimizeId ) {
769+
$this->optimizeId = $optimizeId;
770+
return $this;
771+
}
748772
}

src/Ipunkt/LaravelAnalytics/Providers/NoAnalytics.php

+11
Original file line numberDiff line numberDiff line change
@@ -316,5 +316,16 @@ public function cspNonce()
316316
*/
317317
public function setTrackingId( $trackingId ) {
318318
return $this;
319+
}
320+
321+
/**
322+
* set a custom optimize ID (the GTM-XXXXXX code)
323+
*
324+
* @param string $optimizeId
325+
*
326+
* @return AnalyticsProviderInterface
327+
*/
328+
public function setOptimizeId( $optimizeId ) {
329+
return $this;
319330
}
320331
}

src/config/analytics.php

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/**
1616
* The Google Analytics provider supports the following properties:
1717
* - tracking_id (string)
18+
* - optimize_id (string)
1819
* - tracking_domain (string:auto) - default will be 'auto' if config property not exists
1920
* - tracker_name (string:t0) - default will be 't0' if config property not exists
2021
* - display_features (bool) - default will be false if no config property exists
@@ -30,6 +31,12 @@
3031
*/
3132
'tracking_id' => env('ANALYTICS_TRACKING_ID', 'UA-XXXXXXXX-1'),
3233

34+
/**
35+
* Optimize ID
36+
* Format example: GTM-XXXXXX
37+
*/
38+
'optimize_id' => env('ANALYTICS_OPTIMIZE_ID', ''),
39+
3340
/**
3441
* Tracking Domain
3542
*/

0 commit comments

Comments
 (0)