Skip to content

Commit 91370e3

Browse files
authored
Merge branch 'dev' into tracking
2 parents 03f3dd4 + 08f65f7 commit 91370e3

9 files changed

Lines changed: 34 additions & 51 deletions

File tree

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## About
44

5-
This modules integrates Google Analytics into your shop. It allows you to gain clear insights into important metrics about your customers.
5+
Gain clear insights into important metrics about your customers, using Google Analytics.
66

77
To use it, you will need to create a Google Analytics account and insert your Google Analytics Identifier into the Module configuration page.
88

classes/Form/ConfigurationForm.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ public function generate()
131131
],
132132
[
133133
'type' => 'switch',
134-
'label' => $this->module->l('Disable Back Office Tracking'),
135-
'name' => 'GA_TRACK_BACKOFFICE_DISABLED',
136-
'hint' => $this->module->l('Use this option to disable the tracking inside the Back Office'),
134+
'label' => $this->module->l('Enable Back Office Tracking'),
135+
'name' => 'GA_TRACK_BACKOFFICE_ENABLED',
136+
'hint' => $this->module->l('Use this option to enable the tracking inside the Back Office'),
137137
'values' => [
138138
[
139139
'id' => 'ga_track_backoffice',
@@ -191,7 +191,7 @@ public function generate()
191191
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
192192
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
193193
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
194-
$helper->fields_value['GA_TRACK_BACKOFFICE_DISABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_DISABLED');
194+
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
195195
$helper->fields_value['GA_CANCELLED_STATES[]'] = json_decode(Configuration::get('GA_CANCELLED_STATES'), true);
196196

197197
return $helper->generateForm($fields_form);
@@ -209,7 +209,7 @@ public function treat()
209209
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
210210
$gaCrossdomainEnabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
211211
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
212-
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_DISABLED');
212+
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
213213
$gaCancelledStates = Tools::getValue('GA_CANCELLED_STATES');
214214

215215
if (!empty($gaAccountId)) {
@@ -234,8 +234,8 @@ public function treat()
234234
}
235235

236236
if (null !== $gaTrackBackOffice) {
237-
Configuration::updateValue('GA_TRACK_BACKOFFICE_DISABLED', (bool) $gaTrackBackOffice);
238-
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Disable Back Office tracking updated successfully'));
237+
Configuration::updateValue('GA_TRACK_BACKOFFICE_ENABLED', (bool) $gaTrackBackOffice);
238+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Enable Back Office tracking updated successfully'));
239239
}
240240

241241
if ($gaCancelledStates === false) {

classes/Hook/HookDisplayBackOfficeHeader.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ public function __construct(Ps_Googleanalytics $module, Context $context)
4848
*/
4949
public function run()
5050
{
51-
if (Configuration::get('GA_TRACK_BACKOFFICE_DISABLED')) {
52-
return '';
53-
}
54-
5551
$js = '';
5652
if (strcmp(Tools::getValue('configure'), $this->module->name) === 0) {
5753
$this->context->controller->addCSS($this->module->getPathUri() . 'views/css/ganalytics.css');

classes/Hook/HookDisplayHeader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ public function run()
5454
return '';
5555
}
5656

57-
if (Configuration::get('GA_TRACK_BACKOFFICE_DISABLED') && $this->backOffice) {
58-
return '';
59-
}
60-
6157
$this->context->controller->addJs($this->module->getPathUri() . 'views/js/GoogleAnalyticActionLib.js');
6258

6359
$shops = Shop::getShops();
@@ -81,6 +77,7 @@ public function run()
8177
$this->context->smarty->assign(
8278
[
8379
'backOffice' => $this->backOffice,
80+
'trackBackOffice' => Configuration::get('GA_TRACK_BACKOFFICE_ENABLED'),
8481
'currentShopId' => $currentShopId,
8582
'userId' => $userId,
8683
'gaAccountId' => Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')),

logo.png

1.99 KB
Loading

ps_googleanalytics.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function __construct()
6666
}
6767

6868
/**
69-
* back office module configuration page content
69+
* Back office module configuration page content
7070
*/
7171
public function getContent()
7272
{
@@ -91,7 +91,8 @@ public function hookDisplayHeader($params, $back_office = false)
9191
}
9292

9393
/**
94-
* To track transactions
94+
* Confirmation page hook.
95+
* This function is run to track transactions.
9596
*/
9697
public function hookDisplayOrderConfirmation($params)
9798
{
@@ -102,7 +103,8 @@ public function hookDisplayOrderConfirmation($params)
102103
}
103104

104105
/**
105-
* hook footer to load JS script for standards actions such as product clicks
106+
* Footer hook.
107+
* This function is run to load JS script for standards actions such as product clicks
106108
*/
107109
public function hookDisplayFooter()
108110
{
@@ -112,7 +114,8 @@ public function hookDisplayFooter()
112114
}
113115

114116
/**
115-
* hook home to display generate the product list associated to home featured, news products and best sellers Modules
117+
* Homepage hook.
118+
* This function is run to manage analytics for product list associated to home featured, news products and best sellers Modules
116119
*/
117120
public function hookDisplayHome()
118121
{
@@ -122,7 +125,8 @@ public function hookDisplayHome()
122125
}
123126

124127
/**
125-
* hook product page footer to load JS for product details view
128+
* Product page footer hook
129+
* This function is run to load JS for product details view
126130
*/
127131
public function hookDisplayFooterProduct($params)
128132
{
@@ -133,7 +137,8 @@ public function hookDisplayFooterProduct($params)
133137
}
134138

135139
/**
136-
* Hook admin order to send transactions and refunds details
140+
* Hook admin order.
141+
* This function is run to send transactions and refunds details
137142
*/
138143
public function hookDisplayAdminOrder()
139144
{
@@ -150,7 +155,8 @@ public function hookDisplayAdminOrder()
150155
}
151156

152157
/**
153-
* admin office header to add google analytics js
158+
* Admin office header hook.
159+
* This function is run to add Google Analytics JavaScript
154160
*/
155161
public function hookDisplayBackOfficeHeader()
156162
{
@@ -160,7 +166,8 @@ public function hookDisplayBackOfficeHeader()
160166
}
161167

162168
/**
163-
* Hook admin office header to add google analytics js
169+
* Product cancel action hook (in Back office).
170+
* This function is run to add Google Analytics JavaScript
164171
*/
165172
public function hookActionProductCancel($params)
166173
{
@@ -180,7 +187,8 @@ public function hookActionOrderStatusPostUpdate($params)
180187
}
181188

182189
/**
183-
* hook save cart event to implement addtocart and remove from cart functionality
190+
* Save cart event hook.
191+
* This function is run to implement 'add to cart' and 'remove from cart' functionalities
184192
*/
185193
public function hookActionCartSave()
186194
{
@@ -209,9 +217,9 @@ protected function _debugLog($function, $log)
209217
}
210218

211219
/**
212-
* This method is trigger at the installation of the module
213-
* - install all module tables
214-
* - register hook used by the module.
220+
* This method is triggered at the installation of the module
221+
* - it installs all module tables
222+
* - it registers the hooks used by this module
215223
*
216224
* @return bool
217225
*/
@@ -230,7 +238,7 @@ public function install()
230238

231239
/**
232240
* Triggered at the uninstall of the module
233-
* - erase tables
241+
* - erases this module SQL tables
234242
*
235243
* @return bool
236244
*/

views/js/GoogleAnalyticActionLib.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,19 @@ var GoogleAnalyticEnhancedECommerce = {
7676
addToCart: function(Product) {
7777
this.add(Product);
7878
ga('ec:setAction', 'add');
79-
ga('send', 'event', 'UX', 'click', 'Add to Cart'); // Send data using an event.
79+
ga('send', 'event', 'UX', 'click', 'Add to Cart');
8080
},
8181

8282
removeFromCart: function(Product) {
8383
this.add(Product);
8484
ga('ec:setAction', 'remove');
85-
ga('send', 'event', 'UX', 'click', 'Remove From cart'); // Send data using an event.
85+
ga('send', 'event', 'UX', 'click', 'Remove From cart');
8686
},
8787

8888
addProductImpression: function(Product) {
89-
//ga('send', 'pageview');
9089
},
9190

92-
/**
93-
id, type, affiliation, revenue, tax, shipping and coupon.
94-
**/
91+
9592
refundByOrderId: function(Order) {
9693
/**
9794
* Refund an entire transaction.
@@ -103,11 +100,6 @@ var GoogleAnalyticEnhancedECommerce = {
103100
},
104101

105102
refundByProduct: function(Order) {
106-
/**
107-
* Refund a single product.
108-
**/
109-
//this.add(Product);
110-
111103
ga('ec:setAction', 'refund', {
112104
'id': Order.id, // Transaction ID is required for partial refund.
113105
});
@@ -148,8 +140,6 @@ var GoogleAnalyticEnhancedECommerce = {
148140
},
149141

150142
addTransaction: function(Order) {
151-
152-
//this.add(Product);
153143
ga('ec:setAction', 'purchase', Order);
154144
ga('send', 'event','Transaction','purchase', {
155145
'hitCallback': function() {

views/templates/hook/ga_tag.tpl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,3 @@
2828
</script>
2929
{/literal}
3030
{/if}
31-
32-
{if ($jsState != 1 && $isBackoffice === true)}
33-
{literal}
34-
<script type="text/javascript">
35-
ga('send', 'pageview');
36-
</script>
37-
{/literal}
38-
{/if}

views/templates/hook/ps_googleanalytics.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
{if $gaAnonymizeEnabled}
4545
ga('set', 'anonymizeIp', true);
4646
{/if}
47-
{if $backOffice}
47+
{if $backOffice && !$trackBackOffice}
4848
ga('set', 'nonInteraction', true);
4949
{else}
5050
ga('send', 'pageview');

0 commit comments

Comments
 (0)