File tree 3 files changed +29
-1
lines changed
app/code/Magento/GoogleAnalytics
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -80,8 +80,13 @@ public function getPageTrackingCode($accountId)
80
80
$ optPageURL = ", ' " . $ this ->escapeHtmlAttr ($ pageName , false ) . "' " ;
81
81
}
82
82
83
+ $ anonymizeIp = "" ;
84
+ if ($ this ->_googleAnalyticsData ->isAnonymizedIpActive ()) {
85
+ $ anonymizeIp = "\nga('set', 'anonymizeIp', true); " ;
86
+ }
87
+
83
88
return "\nga('create', ' " . $ this ->escapeHtmlAttr ($ accountId , false )
84
- . ", 'auto'); \nga('send', 'pageview' {$ optPageURL }); \n" ;
89
+ . ", 'auto'); { $ anonymizeIp } \nga('send', 'pageview' {$ optPageURL }); \n" ;
85
90
}
86
91
87
92
/**
@@ -105,6 +110,7 @@ public function getOrdersTrackingCode()
105
110
$ result = [];
106
111
107
112
$ result [] = "ga('require', 'ec', 'ec.js'); " ;
113
+
108
114
foreach ($ collection as $ order ) {
109
115
if ($ order ->getIsVirtual ()) {
110
116
$ address = $ order ->getBillingAddress ();
Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
23
23
24
24
const XML_PATH_ACCOUNT = 'google/analytics/account ' ;
25
25
26
+ const XML_PATH_ANONYMIZE = 'google/analytics/anonymize ' ;
27
+
26
28
/**
27
29
* Whether GA is ready to use
28
30
*
@@ -34,4 +36,16 @@ public function isGoogleAnalyticsAvailable($store = null)
34
36
$ accountId = $ this ->scopeConfig ->getValue (self ::XML_PATH_ACCOUNT , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , $ store );
35
37
return $ accountId && $ this ->scopeConfig ->isSetFlag (self ::XML_PATH_ACTIVE , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , $ store );
36
38
}
39
+
40
+ /**
41
+ * Whether anonymized IPs are active
42
+ *
43
+ * @param null|string|bool|int|Store $store
44
+ * @return bool
45
+ */
46
+ public function isAnonymizedIpActive ($ store = null ) {
47
+ $ anonymize = $ this ->scopeConfig ->getValue (self ::XML_PATH_ANONYMIZE , \Magento \Store \Model \ScopeInterface::SCOPE_STORE , $ store );
48
+ return $ anonymize ;
49
+ }
50
+
37
51
}
Original file line number Diff line number Diff line change 23
23
<field id =" */*/active" >1</field >
24
24
</depends >
25
25
</field >
26
+
27
+ <field id =" anonymize" translate =" label" type =" select" sortOrder =" 30" showInDefault =" 1" showInWebsite =" 1" showInStore =" 1" >
28
+ <label >Anonymize IP</label >
29
+ <source_model >Magento\Config\Model\Config\Source\Yesno</source_model >
30
+ <depends >
31
+ <field id =" */*/active" >1</field >
32
+ </depends >
33
+ </field >
26
34
</group >
27
35
</section >
28
36
</system >
You can’t perform that action at this time.
0 commit comments