Skip to content

Commit

Permalink
refactoring; add anonymize flag to Magento\GoogleAnalytics\Block\Ga.p…
Browse files Browse the repository at this point in the history
…hp->getOrdersTrackingCode
  • Loading branch information
thomas-villagers committed Feb 4, 2017
1 parent f298ef5 commit ed86a75
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions app/code/Magento/GoogleAnalytics/Block/Ga.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,13 @@ public function getPageTrackingCode($accountId)
$optPageURL = ", '" . $this->escapeHtmlAttr($pageName, false) . "'";
}

$anonymizeIp = "false";
$anonymizeIp = "";
if ($this->_googleAnalyticsData->isAnonymizedIpActive()) {
$anonymizeIp = "true";
$anonymizeIp = ", {'anonymizeIp': true}";
}

return "\nga('create', '{$this->escapeJsQuote(
$accountId
)}', 'auto');\nga('send', 'pageview'{$optPageURL}, {'anonymizeIp' : {$anonymizeIp}});\n";
return "\nga('create', '" . $this->escapeHtmlAttr($accountId, false)
. ", 'auto');\nga('send', 'pageview'{$optPageURL}{$anonymizeIp});\n";
}

/**
Expand All @@ -111,6 +110,12 @@ public function getOrdersTrackingCode()
$result = [];

$result[] = "ga('require', 'ec', 'ec.js');";

$anonymizeIp = "";
if ($this->_googleAnalyticsData->isAnonymizedIpActive()) {
$anonymizeIp = ", {'anonymizeIp': true}";
}

foreach ($collection as $order) {
if ($order->getIsVirtual()) {
$address = $order->getBillingAddress();
Expand Down Expand Up @@ -148,7 +153,7 @@ public function getOrdersTrackingCode()
$order->getBaseShippingAmount()
);

$result[] = "ga('send', 'pageview');";
$result[] = "ga('send', 'pageview'{$anonymizeIp});";
}
return implode("\n", $result);
}
Expand Down

0 comments on commit ed86a75

Please sign in to comment.