21
21
*/
22
22
class Mage_GoogleAnalytics_Block_Ga extends Mage_Core_Block_Template
23
23
{
24
- /**
25
- * @deprecated after 1.4.1.1
26
- * @see self::_getOrdersTrackingCode()
27
- * @return string
28
- */
29
- public function getQuoteOrdersHtml ()
30
- {
31
- return '' ;
32
- }
33
-
34
- /**
35
- * @deprecated after 1.4.1.1
36
- * self::_getOrdersTrackingCode()
37
- * @return string
38
- */
39
- public function getOrderHtml ()
40
- {
41
- return '' ;
42
- }
43
-
44
- /**
45
- * @deprecated after 1.4.1.1
46
- * @see _toHtml()
47
- * @return string
48
- */
49
- public function getAccount ()
50
- {
51
- return '' ;
52
- }
53
-
54
- /**
55
- * Get a specific page name (may be customized via layout)
56
- *
57
- * @return string
58
- * @deprecated
59
- */
60
- public function getPageName ()
61
- {
62
- return $ this ->_getData ('page_name ' ) ?? '' ;
63
- }
64
-
65
24
/**
66
25
* Render regular page tracking javascript code
67
26
* The custom "page name" may be set from layout or somewhere else. It must start from slash.
@@ -75,11 +34,9 @@ protected function _getPageTrackingCode($accountId)
75
34
$ helper = $ this ->helper ('googleanalytics ' );
76
35
if ($ helper ->isUseAnalytics4 ()) {
77
36
return $ this ->_getPageTrackingCodeAnalytics4 ($ accountId );
78
- } elseif ($ helper ->isUseUniversalAnalytics ()) {
79
- return $ this ->_getPageTrackingCodeUniversal ($ accountId );
80
- } else {
81
- return $ this ->_getPageTrackingCodeAnalytics ($ accountId );
82
37
}
38
+
39
+ return '' ;
83
40
}
84
41
85
42
/**
@@ -125,14 +82,11 @@ protected function _getPageTrackingCodeAnalytics4($accountId)
125
82
*
126
83
* @param string $accountId
127
84
* @return string
85
+ * @deprecated
128
86
*/
129
87
protected function _getPageTrackingCodeUniversal ($ accountId )
130
88
{
131
- return "
132
- ga('create', ' {$ this ->jsQuoteEscape ($ accountId )}', 'auto');
133
- " . $ this ->_getAnonymizationCode () . "
134
- ga('send', 'pageview');
135
- " ;
89
+ return '' ;
136
90
}
137
91
138
92
/**
@@ -143,19 +97,11 @@ protected function _getPageTrackingCodeUniversal($accountId)
143
97
* @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gaq.html
144
98
* @param string $accountId
145
99
* @return string
100
+ * @deprecated
146
101
*/
147
102
protected function _getPageTrackingCodeAnalytics ($ accountId )
148
103
{
149
- $ pageName = trim ($ this ->getPageName ());
150
- $ optPageURL = '' ;
151
- if ($ pageName && preg_match ('/^\/.*/i ' , $ pageName )) {
152
- $ optPageURL = ", ' {$ this ->jsQuoteEscape ($ pageName )}' " ;
153
- }
154
- return "
155
- _gaq.push(['_setAccount', ' {$ this ->jsQuoteEscape ($ accountId )}']);
156
- " . $ this ->_getAnonymizationCode () . "
157
- _gaq.push(['_trackPageview' {$ optPageURL }]);
158
- " ;
104
+ return '' ;
159
105
}
160
106
161
107
/**
@@ -170,65 +116,9 @@ protected function _getOrdersTrackingCode()
170
116
$ helper = $ this ->helper ('googleanalytics ' );
171
117
if ($ helper ->isUseAnalytics4 ()) {
172
118
return $ this ->_getOrdersTrackingCodeAnalytics4 ();
173
- } elseif ($ helper ->isUseUniversalAnalytics ()) {
174
- return $ this ->_getOrdersTrackingCodeUniversal ();
175
119
}
176
120
177
- return $ this ->_getOrdersTrackingCodeAnalytics ();
178
- }
179
-
180
- /**
181
- * Render information about specified orders and their items
182
- *
183
- * @return string
184
- * @throws Mage_Core_Model_Store_Exception
185
- */
186
- protected function _getOrdersTrackingCodeUniversal ()
187
- {
188
- $ orderIds = $ this ->getOrderIds ();
189
- if (empty ($ orderIds ) || !is_array ($ orderIds )) {
190
- return ;
191
- }
192
- $ collection = Mage::getResourceModel ('sales/order_collection ' )
193
- ->addFieldToFilter ('entity_id ' , ['in ' => $ orderIds ]);
194
- $ result = [];
195
- $ result [] = "ga('require', 'ecommerce') " ;
196
- foreach ($ collection as $ order ) {
197
- $ result [] = sprintf (
198
- "ga('ecommerce:addTransaction', {
199
- 'id': '%s',
200
- 'affiliation': '%s',
201
- 'revenue': '%s',
202
- 'tax': '%s',
203
- 'shipping': '%s'
204
- }); " ,
205
- $ order ->getIncrementId (),
206
- $ this ->jsQuoteEscape (Mage::app ()->getStore ()->getFrontendName ()),
207
- $ order ->getBaseGrandTotal (),
208
- $ order ->getBaseTaxAmount (),
209
- $ order ->getBaseShippingAmount ()
210
- );
211
- foreach ($ order ->getAllVisibleItems () as $ item ) {
212
- $ result [] = sprintf (
213
- "ga('ecommerce:addItem', {
214
- 'id': '%s',
215
- 'sku': '%s',
216
- 'name': '%s',
217
- 'category': '%s',
218
- 'price': '%s',
219
- 'quantity': '%s'
220
- }); " ,
221
- $ order ->getIncrementId (),
222
- $ this ->jsQuoteEscape ($ item ->getSku ()),
223
- $ this ->jsQuoteEscape ($ item ->getName ()),
224
- null , // there is no "category" defined for the order item
225
- $ item ->getBasePrice (),
226
- $ item ->getQtyOrdered ()
227
- );
228
- }
229
- $ result [] = "ga('ecommerce:send'); " ;
230
- }
231
- return implode ("\n" , $ result );
121
+ return '' ;
232
122
}
233
123
234
124
/**
@@ -501,97 +391,6 @@ protected function _getOrdersTrackingCodeAnalytics4()
501
391
}
502
392
503
393
/**
504
- * Render information about specified orders and their items
505
- *
506
- * @link http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
507
- * @return string
508
- * @throws Mage_Core_Model_Store_Exception
509
- */
510
- protected function _getOrdersTrackingCodeAnalytics ()
511
- {
512
- $ orderIds = $ this ->getOrderIds ();
513
- if (empty ($ orderIds ) || !is_array ($ orderIds )) {
514
- return ;
515
- }
516
- $ collection = Mage::getResourceModel ('sales/order_collection ' )
517
- ->addFieldToFilter ('entity_id ' , ['in ' => $ orderIds ]);
518
- $ result = [];
519
- foreach ($ collection as $ order ) {
520
- if ($ order ->getIsVirtual ()) {
521
- $ address = $ order ->getBillingAddress ();
522
- } else {
523
- $ address = $ order ->getShippingAddress ();
524
- }
525
- $ result [] = sprintf (
526
- "_gaq.push(['_addTrans', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s']); " ,
527
- $ order ->getIncrementId (),
528
- $ this ->jsQuoteEscape (Mage::app ()->getStore ()->getFrontendName ()),
529
- $ order ->getBaseGrandTotal (),
530
- $ order ->getBaseTaxAmount (),
531
- $ order ->getBaseShippingAmount (),
532
- $ this ->jsQuoteEscape (Mage::helper ('core ' )->escapeHtml ($ address ->getCity ())),
533
- $ this ->jsQuoteEscape (Mage::helper ('core ' )->escapeHtml ($ address ->getRegion ())),
534
- $ this ->jsQuoteEscape (Mage::helper ('core ' )->escapeHtml ($ address ->getCountry ()))
535
- );
536
- foreach ($ order ->getAllVisibleItems () as $ item ) {
537
- $ result [] = sprintf (
538
- "_gaq.push(['_addItem', '%s', '%s', '%s', '%s', '%s', '%s']); " ,
539
- $ order ->getIncrementId (),
540
- $ this ->jsQuoteEscape ($ item ->getSku ()),
541
- $ this ->jsQuoteEscape ($ item ->getName ()),
542
- null , // there is no "category" defined for the order item
543
- $ item ->getBasePrice (),
544
- $ item ->getQtyOrdered ()
545
- );
546
- }
547
- $ result [] = "_gaq.push(['_trackTrans']); " ;
548
- }
549
- return implode ("\n" , $ result );
550
- }
551
-
552
- /**
553
- * Render IP anonymization code for page tracking javascript code
554
- *
555
- * @return string
556
- */
557
- protected function _getAnonymizationCode ()
558
- {
559
- if (!Mage::helper ('googleanalytics ' )->isIpAnonymizationEnabled ()) {
560
- return '' ;
561
- }
562
-
563
- /** @var Mage_GoogleAnalytics_Helper_Data $helper */
564
- $ helper = $ this ->helper ('googleanalytics ' );
565
- if ($ helper ->isUseUniversalAnalytics ()) {
566
- return $ this ->_getAnonymizationCodeUniversal ();
567
- }
568
-
569
- return $ this ->_getAnonymizationCodeAnalytics ();
570
- }
571
-
572
- /**
573
- * Render IP anonymization code for page tracking javascript universal analytics code
574
- *
575
- * @return string
576
- */
577
- protected function _getAnonymizationCodeUniversal ()
578
- {
579
- return "ga('set', 'anonymizeIp', true); " ;
580
- }
581
-
582
- /**
583
- * Render IP anonymization code for page tracking javascript google analytics code
584
- *
585
- * @return string
586
- */
587
- protected function _getAnonymizationCodeAnalytics ()
588
- {
589
- return "_gaq.push (['_gat._anonymizeIp']); " ;
590
- }
591
-
592
- /**
593
- * Is ga available
594
- *
595
394
* @return bool
596
395
*/
597
396
protected function _isAvailable ()
0 commit comments