Skip to content

Commit 4459830

Browse files
authored
Merge pull request #132 from Hlavtox/last-polish
Last improvements
2 parents bc3ac43 + a7ad285 commit 4459830

4 files changed

Lines changed: 22 additions & 18 deletions

File tree

classes/Form/ConfigurationForm.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public function treat()
227227
// Check if multistore is active
228228
$is_multistore_active = Shop::isFeatureActive();
229229

230-
$treatmentResult = '';
231230
$gaAccountId = Tools::getValue('GA_ACCOUNT_ID');
232231
$gaV4Enabled = Tools::getValue('GA_V4_ENABLED');
233232
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
@@ -239,41 +238,34 @@ public function treat()
239238
if (!empty($gaAccountId)) {
240239
Configuration::updateValue('GA_ACCOUNT_ID', $gaAccountId);
241240
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
242-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Account ID updated successfully', [], 'Modules.GAnalytics.Admin'));
243241
}
244242

245243
if (null !== $gaV4Enabled) {
246244
Configuration::updateValue('GA_V4_ENABLED', (bool) $gaV4Enabled);
247-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for Google Analytics 4 updated successfully'));
248245
}
249246

250247
if (null !== $gaUserIdEnabled) {
251248
Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
252-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for User ID updated successfully', [], 'Modules.GAnalytics.Admin'));
253249
}
254250

255251
if ($is_multistore_active) {
256252
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
257-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for Cross-Domain updated successfully', [], 'Modules.GAnalytics.Admin'));
258253
}
259254

260255
if (null !== $gaAnonymizeEnabled) {
261256
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
262-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for Anonymize IP updated successfully', [], 'Modules.GAnalytics.Admin'));
263257
}
264258

265259
if (null !== $gaTrackBackOffice) {
266260
Configuration::updateValue('GA_TRACK_BACKOFFICE_ENABLED', (bool) $gaTrackBackOffice);
267-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for Enable Back Office tracking updated successfully.', [], 'Modules.GAnalytics.Admin'));
268261
}
269262

270263
if ($gaCancelledStates === false) {
271264
Configuration::updateValue('GA_CANCELLED_STATES', '');
272265
} else {
273266
Configuration::updateValue('GA_CANCELLED_STATES', json_encode($gaCancelledStates));
274267
}
275-
$treatmentResult .= $this->module->displayConfirmation($this->module->trans('Settings for canceled order states updated successfully.', [], 'Modules.GAnalytics.Admin'));
276268

277-
return $treatmentResult;
269+
return $this->module->displayConfirmation($this->module->trans('Settings updated successfully.', [], 'Modules.GAnalytics.Admin'));
278270
}
279271
}

classes/GoogleAnalyticsTools.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace PrestaShop\Module\Ps_Googleanalytics;
2222

23+
use Configuration;
24+
2325
class GoogleAnalyticsTools
2426
{
2527
/**
@@ -163,6 +165,13 @@ public function addProductClick($products, $currencyIsoCode)
163165
],
164166
];
165167

168+
// Add send_to parameter to avoid sending extra events
169+
// to other gtag configs (Ads for example).
170+
$eventData = array_merge(
171+
['send_to' => Configuration::get('GA_ACCOUNT_ID')],
172+
$eventData
173+
);
174+
166175
$productId = explode('-', $product['id']);
167176
$js .= '$(\'article[data-id-product="' . $productId[0] . '"] a.quick-view\').on(
168177
"click",
@@ -282,6 +291,13 @@ public function jsonEncodeWithBlacklist($data, $ignoredKeys = [])
282291
*/
283292
public function renderEvent($eventName, $eventData, $ignoredKeys = [])
284293
{
294+
// Automatically add send_to parameter to all events to avoid sending extra events
295+
// to other gtag configs (Ads for example).
296+
$eventData = array_merge(
297+
['send_to' => Configuration::get('GA_ACCOUNT_ID')],
298+
$eventData
299+
);
300+
285301
return sprintf(
286302
'gtag("event", "%1$s", %2$s);',
287303
$eventName,

ps_googleanalytics.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ public function __construct()
7474
public function getContent()
7575
{
7676
$configurationForm = new PrestaShop\Module\Ps_Googleanalytics\Form\ConfigurationForm($this);
77-
$formOutput = '';
77+
$output = '';
7878

7979
if (Tools::isSubmit('submit' . $this->name)) {
80-
$formOutput = $configurationForm->treat();
80+
$output .= $configurationForm->treat();
8181
}
8282

83-
$formOutput .= $configurationForm->generate();
83+
$output .= $this->display(__FILE__, './views/templates/admin/configuration.tpl');
84+
$output .= $configurationForm->generate();
8485

85-
return $this->display(__FILE__, './views/templates/admin/configuration.tpl') . $formOutput;
86+
return $output;
8687
}
8788

8889
public function hookDisplayHeader($params, $back_office = false)

views/css/ganalytics.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
1717
* International Registered Trademark & Property of PrestaShop SA
1818
*/
19-
#content .panel {
20-
margin: 0 auto;
21-
max-width: 1300px;
22-
}
23-
2419
.google-analytics-advantages-list, .google-analytics-create {
2520
margin-bottom: 1rem;
2621
}

0 commit comments

Comments
 (0)