Skip to content

Commit 15864bc

Browse files
committed
Remove universal analytics
1 parent c504048 commit 15864bc

21 files changed

Lines changed: 307 additions & 845 deletions

classes/Database/Install.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public function registerHooks()
101101
return $this->module->registerHook('displayHeader') &&
102102
$this->module->registerHook('displayAdminOrder') &&
103103
$this->module->registerHook('displayBeforeBodyClosingTag') &&
104-
$this->module->registerHook('displayFooter') &&
105104
$this->module->registerHook('displayFooterProduct') &&
106105
$this->module->registerHook('displayOrderConfirmation') &&
107106
$this->module->registerHook('actionProductCancel') &&

classes/Form/ConfigurationForm.php

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use HelperForm;
2727
use OrderState;
2828
use Ps_Googleanalytics;
29-
use Shop;
3029
use Tools;
3130

3231
class ConfigurationForm
@@ -45,9 +44,6 @@ public function __construct(Ps_Googleanalytics $module)
4544
*/
4645
public function generate()
4746
{
48-
// Check if multistore is active
49-
$is_multistore_active = Shop::isFeatureActive();
50-
5147
// Get default language
5248
$default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
5349

@@ -87,31 +83,13 @@ public function generate()
8783
'title' => $this->module->trans('Settings', [], 'Modules.Googleanalytics.Admin'),
8884
],
8985
'input' => [
90-
[
91-
'type' => 'switch',
92-
'label' => $this->module->trans('Enable Google Analytics 4', [], 'Modules.Googleanalytics.Admin'),
93-
'name' => 'GA_V4_ENABLED',
94-
'values' => [
95-
[
96-
'id' => 'GA_V4_ENABLED',
97-
'value' => 1,
98-
'label' => $this->module->trans('Yes', [], 'Modules.Googleanalytics.Admin'),
99-
],
100-
[
101-
'id' => 'GA_V4_ENABLED',
102-
'value' => 0,
103-
'label' => $this->module->trans('No', [], 'Modules.Googleanalytics.Admin'),
104-
],
105-
],
106-
'desc' => $this->module->trans('Universal analytics will stop processing data on July 1, 2023. We recommend switching to Google Analytics 4 as soon as possible.', [], 'Modules.Googleanalytics.Admin'),
107-
],
10886
[
10987
'type' => 'text',
11088
'label' => $this->module->trans('Google Analytics Tracking ID', [], 'Modules.Googleanalytics.Admin'),
11189
'name' => 'GA_ACCOUNT_ID',
11290
'size' => 20,
11391
'required' => true,
114-
'desc' => $this->module->trans('This information is available in your Google Analytics account. GA4 tracking ID starts with "G-", Universal Analytics with "UA-".', [], 'Modules.Googleanalytics.Admin'),
92+
'desc' => $this->module->trans('This information is available in your Google Analytics account. Google Analytics 4 tracking ID starts with "G-".', [], 'Modules.Googleanalytics.Admin'),
11593
],
11694
[
11795
'type' => 'switch',
@@ -185,31 +163,9 @@ public function generate()
185163
],
186164
];
187165

188-
if ($is_multistore_active) {
189-
$fields_form[0]['form']['input'][] = [
190-
'type' => 'switch',
191-
'label' => $this->module->trans('Enable Cross-Domain tracking', [], 'Modules.Googleanalytics.Admin'),
192-
'name' => 'GA_CROSSDOMAIN_ENABLED',
193-
'values' => [
194-
[
195-
'id' => 'ga_crossdomain_enabled',
196-
'value' => 1,
197-
'label' => $this->module->trans('Yes', [], 'Modules.Googleanalytics.Admin'),
198-
],
199-
[
200-
'id' => 'ga_crossdomain_disabled',
201-
'value' => 0,
202-
'label' => $this->module->trans('No', [], 'Modules.Googleanalytics.Admin'),
203-
],
204-
],
205-
];
206-
}
207-
208166
// Load current value
209167
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
210-
$helper->fields_value['GA_V4_ENABLED'] = Configuration::get('GA_V4_ENABLED');
211168
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
212-
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
213169
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
214170
$helper->fields_value['GA_TRACK_BACKOFFICE_ENABLED'] = Configuration::get('GA_TRACK_BACKOFFICE_ENABLED');
215171
$helper->fields_value['GA_CANCELLED_STATES[]'] = json_decode(Configuration::get('GA_CANCELLED_STATES'), true);
@@ -224,13 +180,8 @@ public function generate()
224180
*/
225181
public function treat()
226182
{
227-
// Check if multistore is active
228-
$is_multistore_active = Shop::isFeatureActive();
229-
230183
$gaAccountId = Tools::getValue('GA_ACCOUNT_ID');
231-
$gaV4Enabled = Tools::getValue('GA_V4_ENABLED');
232184
$gaUserIdEnabled = Tools::getValue('GA_USERID_ENABLED');
233-
$gaCrossdomainEnabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
234185
$gaAnonymizeEnabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
235186
$gaTrackBackOffice = Tools::getValue('GA_TRACK_BACKOFFICE_ENABLED');
236187
$gaCancelledStates = Tools::getValue('GA_CANCELLED_STATES');
@@ -240,18 +191,10 @@ public function treat()
240191
Configuration::updateValue('GANALYTICS_CONFIGURATION_OK', true);
241192
}
242193

243-
if (null !== $gaV4Enabled) {
244-
Configuration::updateValue('GA_V4_ENABLED', (bool) $gaV4Enabled);
245-
}
246-
247194
if (null !== $gaUserIdEnabled) {
248195
Configuration::updateValue('GA_USERID_ENABLED', (bool) $gaUserIdEnabled);
249196
}
250197

251-
if ($is_multistore_active) {
252-
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool) $gaCrossdomainEnabled);
253-
}
254-
255198
if (null !== $gaAnonymizeEnabled) {
256199
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool) $gaAnonymizeEnabled);
257200
}

classes/GoogleAnalyticsTools.php

Lines changed: 75 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@
2424

2525
class GoogleAnalyticsTools
2626
{
27-
/**
28-
* @var bool
29-
*/
30-
protected $isV4Enabled = false;
31-
32-
public function __construct($isV4Enabled = false)
33-
{
34-
$this->isV4Enabled = $isV4Enabled;
35-
}
36-
3727
/**
3828
* filter
3929
*
@@ -65,70 +55,38 @@ public function addTransaction($products, $transaction)
6555
return;
6656
}
6757

68-
if ($this->isV4Enabled) {
69-
$callbackData = [
70-
'orderid' => $transaction['id'],
71-
'customer' => $transaction['customer'],
72-
];
73-
74-
$eventData = [
75-
'transaction_id' => (int) $transaction['id'],
76-
'affiliation' => $transaction['affiliation'],
77-
'value' => (float) $transaction['revenue'],
78-
'tax' => (float) $transaction['tax'],
79-
'shipping' => (float) $transaction['shipping'],
80-
'currency' => $transaction['currency'],
81-
'items' => [],
82-
'event_callback' => "function() {
83-
$.get('" . $transaction['url'] . "', " . json_encode($callbackData, JSON_UNESCAPED_UNICODE) . ');
84-
}',
58+
$callbackData = [
59+
'orderid' => $transaction['id'],
60+
'customer' => $transaction['customer'],
61+
];
62+
63+
$eventData = [
64+
'transaction_id' => (int) $transaction['id'],
65+
'affiliation' => $transaction['affiliation'],
66+
'value' => (float) $transaction['revenue'],
67+
'tax' => (float) $transaction['tax'],
68+
'shipping' => (float) $transaction['shipping'],
69+
'currency' => $transaction['currency'],
70+
'items' => [],
71+
'event_callback' => "function() {
72+
$.get('" . $transaction['url'] . "', " . json_encode($callbackData, JSON_UNESCAPED_UNICODE) . ');
73+
}',
74+
];
75+
76+
foreach ($products as $product) {
77+
$eventData['items'][] = [
78+
'item_id' => (int) $product['id'],
79+
'item_name' => $product['name'],
80+
'quantity' => (int) $product['quantity'],
81+
'price' => (float) $product['price'],
8582
];
86-
87-
foreach ($products as $product) {
88-
$eventData['items'][] = [
89-
'item_id' => (int) $product['id'],
90-
'item_name' => $product['name'],
91-
'quantity' => (int) $product['quantity'],
92-
'price' => (float) $product['price'],
93-
];
94-
}
95-
96-
$js = $this->renderEvent(
97-
'purchase',
98-
$eventData,
99-
['event_callback']
100-
);
101-
} else {
102-
unset($transaction['currency']);
103-
$js = '';
104-
foreach ($products as $product) {
105-
$js .= 'MBG.add(' . json_encode($product) . ');';
106-
}
107-
$js .= 'MBG.addTransaction(' . json_encode($transaction) . ');';
10883
}
10984

110-
return $js;
111-
}
112-
113-
/**
114-
* add product impression js and product click js
115-
*
116-
* @param array $products
117-
*
118-
* @return string|void
119-
*/
120-
public function addProductImpression($products)
121-
{
122-
if (!is_array($products)) {
123-
return;
124-
}
125-
126-
$js = '';
127-
if (!$this->isV4Enabled) {
128-
foreach ($products as $product) {
129-
$js .= 'MBG.add(' . json_encode($product) . ",'',true);";
130-
}
131-
}
85+
$js = $this->renderEvent(
86+
'purchase',
87+
$eventData,
88+
['event_callback']
89+
);
13290

13391
return $js;
13492
}
@@ -148,41 +106,35 @@ public function addProductClick($products, $currencyIsoCode)
148106
}
149107

150108
$js = '';
151-
if ($this->isV4Enabled) {
152-
foreach ($products as $key => $product) {
153-
$eventData = [
154-
'items' => [
155-
'item_id' => (int) $product['id'],
156-
'item_name' => $product['name'],
157-
'quantity' => (int) $product['quantity'],
158-
'price' => (float) $product['price'],
159-
'currency' => $currencyIsoCode,
160-
'index' => (int) $product['position'],
161-
'item_brand' => $product['brand'],
162-
'item_category' => $product['category'],
163-
'item_list_id' => $product['list'],
164-
'item_variant' => $product['variant'],
165-
],
166-
];
109+
foreach ($products as $key => $product) {
110+
$eventData = [
111+
'items' => [
112+
'item_id' => (int) $product['id'],
113+
'item_name' => $product['name'],
114+
'quantity' => (int) $product['quantity'],
115+
'price' => (float) $product['price'],
116+
'currency' => $currencyIsoCode,
117+
'index' => (int) $product['position'],
118+
'item_brand' => $product['brand'],
119+
'item_category' => $product['category'],
120+
'item_list_id' => $product['list'],
121+
'item_variant' => $product['variant'],
122+
],
123+
];
167124

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-
);
125+
// Add send_to parameter to avoid sending extra events
126+
// to other gtag configs (Ads for example).
127+
$eventData = array_merge(
128+
['send_to' => Configuration::get('GA_ACCOUNT_ID')],
129+
$eventData
130+
);
174131

175-
$productId = explode('-', $product['id']);
176-
$js .= '$(\'article[data-id-product="' . $productId[0] . '"] a.quick-view\').on(
177-
"click",
178-
function() {
179-
gtag("event", "select_item", ' . json_encode($eventData, JSON_UNESCAPED_UNICODE) . ')
180-
});';
181-
}
182-
} else {
183-
foreach ($products as $product) {
184-
$js .= 'MBG.addProductClick(' . json_encode($product) . ');';
185-
}
132+
$productId = explode('-', $product['id']);
133+
$js .= '$(\'article[data-id-product="' . $productId[0] . '"] a.quick-view\').on(
134+
"click",
135+
function() {
136+
gtag("event", "select_item", ' . json_encode($eventData, JSON_UNESCAPED_UNICODE) . ')
137+
});';
186138
}
187139

188140
return $js;
@@ -202,55 +154,26 @@ public function addProductClickByHttpReferal($products, $currencyIsoCode)
202154
}
203155

204156
$js = '';
205-
if ($this->isV4Enabled) {
206-
foreach ($products as $key => $product) {
207-
$eventData = [
208-
'items' => [
209-
'item_id' => (int) $product['id'],
210-
'item_name' => $product['name'],
211-
'quantity' => (int) $product['quantity'],
212-
'price' => (float) $product['price'],
213-
'currency' => $currencyIsoCode,
214-
'index' => (int) $product['position'],
215-
'item_brand' => $product['brand'],
216-
'item_category' => $product['category'],
217-
'item_list_id' => $product['list'],
218-
'item_variant' => $product['variant'],
219-
],
220-
];
221-
222-
$js .= $this->renderEvent(
223-
'select_item',
224-
$eventData
225-
);
226-
}
227-
} else {
228-
foreach ($products as $product) {
229-
$js .= 'MBG.addProductClickByHttpReferal(' . json_encode($product) . ');';
230-
}
231-
}
232-
233-
return $js;
234-
}
235-
236-
/**
237-
* Add product checkout info
238-
*
239-
* @param array $products
240-
*
241-
* @return string|void
242-
*/
243-
public function addProductFromCheckout($products)
244-
{
245-
if (!is_array($products)) {
246-
return;
247-
}
157+
foreach ($products as $key => $product) {
158+
$eventData = [
159+
'items' => [
160+
'item_id' => (int) $product['id'],
161+
'item_name' => $product['name'],
162+
'quantity' => (int) $product['quantity'],
163+
'price' => (float) $product['price'],
164+
'currency' => $currencyIsoCode,
165+
'index' => (int) $product['position'],
166+
'item_brand' => $product['brand'],
167+
'item_category' => $product['category'],
168+
'item_list_id' => $product['list'],
169+
'item_variant' => $product['variant'],
170+
],
171+
];
248172

249-
$js = '';
250-
if (!$this->isV4Enabled) {
251-
foreach ($products as $product) {
252-
$js .= 'MBG.add(' . json_encode($product) . ');';
253-
}
173+
$js .= $this->renderEvent(
174+
'select_item',
175+
$eventData
176+
);
254177
}
255178

256179
return $js;

0 commit comments

Comments
 (0)