Skip to content

Commit

Permalink
enable display features + analytics_debug.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcondb committed Nov 4, 2014
1 parent 81c1cc7 commit c80cff7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/ArcticFalcon/LaravelAnalytics/Providers/GoogleAnalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class GoogleAnalytics implements AnalyticsProviderInterface {

private $customDimensions = [];

protected $enableDisplayFeatures = false;

/**
* setting options via constructor
*
Expand All @@ -72,6 +74,7 @@ public function __construct(array $options = array(), TrackingBagInterface $trac
$this->anonymizeIp = (isset($options['anonymize_ip'])) ? $options['anonymize_ip'] : false;
$this->autoTrack = (isset($options['auto_track'])) ? $options['auto_track'] : false;
$this->sandbox = (isset($options['sandbox'])) ? $options['sandbox'] : false;
$this->enableDisplayFeatures = (isset($options['display_features'])) ? $options['display_features'] : false;

if ($this->trackingId === null)
{
Expand Down Expand Up @@ -198,6 +201,22 @@ public function setCustomDimension($index, $value)
$this->customDimensions[$index] = $value;
}

/**
* @return boolean
*/
public function isEnableDisplayFeatures()
{
return $this->enableDisplayFeatures;
}

/**
* @param boolean $enableDisplayFeatures
*/
public function setEnableDisplayFeatures($enableDisplayFeatures)
{
$this->enableDisplayFeatures = $enableDisplayFeatures;
}


/**
* returns the javascript embedding code
Expand All @@ -217,6 +236,11 @@ public function render()
$script[] = "ga('create', '{$this->trackingId}', '{$this->trackingDomain}');";
}

if ($this->enableDisplayFeatures)
{
$script[] = "ga('require', 'displayfeatures');";
}

if ($this->anonymizeIp)
{
$script[] = "ga('set', 'anonymizeIp', true);";
Expand Down Expand Up @@ -254,7 +278,8 @@ public function render()
*/
protected function _getJavascriptTemplateBlockBegin()
{
return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');";
$debug = $this->sandbox? '_debug' : '';
return "<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics{$debug}.js','ga');";
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/config/analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
* Or you can use Analytics::disableAutoTracking(), Analytics::enableAutoTracking()
*/
'auto_track' => true,
'sandbox' => true,
'display_features' => false,

]

Expand Down

0 comments on commit c80cff7

Please sign in to comment.