Skip to content

Commit 08f65f7

Browse files
authored
Merge pull request #77 from Hlavtox/patch-2
Fix backoffice JS code, fix doubled and tripled pageviews, fix echo in hook, fix default BO tracking - for versions up to 1.7.6
2 parents f635297 + b649e99 commit 08f65f7

6 files changed

Lines changed: 13 additions & 25 deletions

File tree

classes/Form/ConfigurationForm.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public function generate()
129129
],
130130
[
131131
'type' => 'switch',
132-
'label' => $this->module->l('Disable Back Office Tracking'),
133-
'name' => 'GA_TRACK_BACKOFFICE_DISABLED',
134-
'hint' => $this->module->l('Use this option to disable the tracking inside the Back Office'),
132+
'label' => $this->module->l('Enable Back Office Tracking'),
133+
'name' => 'GA_TRACK_BACKOFFICE_ENABLED',
134+
'hint' => $this->module->l('Use this option to enable the tracking inside the Back Office'),
135135
'values' => [
136136
[
137137
'id' => 'ga_track_backoffice',
@@ -176,7 +176,7 @@ public function generate()
176176
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
177177
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
178178
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
179-
$helper->fields_value['GA_TRACK_BACKOFFICE_DISABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_DISABLED');
179+
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
180180

181181
return $helper->generateForm($fields_form);
182182
}
@@ -193,7 +193,7 @@ public function treat()
193193
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
194194
$gaCrossdomainEnabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
195195
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
196-
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_DISABLED');
196+
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
197197

198198
if (!empty($gaAccountId)) {
199199
Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
@@ -217,8 +217,8 @@ public function treat()
217217
}
218218

219219
if (null !== $gaTrackBackOffice) {
220-
Configuration::updateValue('GA_TRACK_BACKOFFICE_DISABLED', (bool) $gaTrackBackOffice);
221-
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Disable Back Office tracking updated successfully'));
220+
Configuration::updateValue('GA_TRACK_BACKOFFICE_ENABLED', (bool) $gaTrackBackOffice);
221+
$treatmentResult .= $this->module->displayConfirmation($this->module->l('Settings for Enable Back Office tracking updated successfully'));
222222
}
223223

224224
return $treatmentResult;

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')),

ps_googleanalytics.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,14 @@ public function hookDisplayAdminOrder()
144144
{
145145
$gaTagHandler = new PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler($this, $this->context);
146146

147-
echo $gaTagHandler->generate(
147+
$output = $gaTagHandler->generate(
148148
$this->context->cookie->__get('ga_admin_refund'),
149149
true
150150
);
151151
$this->context->cookie->__unset('ga_admin_refund');
152+
$this->context->cookie->write();
153+
154+
return $output;
152155
}
153156

154157
/**

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)