Skip to content

Commit 1dc9106

Browse files
Merge pull request #12 from PrestaShop/master
Merging unmerged modification
2 parents 354d754 + 46af28f commit 1dc9106

4 files changed

Lines changed: 158 additions & 34 deletions

File tree

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<module>
33
<name>ps_googleanalytics</name>
44
<displayName><![CDATA[Google Analytics]]></displayName>
5-
<version><![CDATA[3.0.3]]></version>
5+
<version><![CDATA[3.0.4]]></version>
66
<description><![CDATA[Gain clear insights into important metrics about your customers, using Google Analytics]]></description>
77
<author><![CDATA[PrestaShop]]></author>
88
<tab><![CDATA[analytics_stats]]></tab>

ps_googleanalytics.php

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ protected function deleteTables()
136136

137137
public function displayForm()
138138
{
139+
// Check if multistore is active
140+
$is_multistore_active = Shop::isFeatureActive();
141+
139142
// Get default language
140143
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
141144

@@ -188,8 +191,7 @@ public function displayForm()
188191
'type' => 'switch',
189192
'label' => $this->l('Enable User ID tracking'),
190193
'name' => 'GA_USERID_ENABLED',
191-
'hint' => $this->l('The User ID is set at the property level. To find a property, click Admin, then select an account and a property. From the Property column, click Tracking Info then User ID'),
192-
'values' => array(
194+
'values' => array(
193195
array(
194196
'id' => 'ga_userid_enabled',
195197
'value' => 1,
@@ -199,8 +201,7 @@ public function displayForm()
199201
'id' => 'ga_userid_disabled',
200202
'value' => 0,
201203
'label' => $this->l('Disabled')
202-
),
203-
),
204+
))
204205
),
205206
array(
206207
'type' => 'switch',
@@ -225,10 +226,31 @@ public function displayForm()
225226
'title' => $this->l('Save'),
226227
)
227228
);
229+
230+
if ($is_multistore_active) {
231+
$fields_form[0]['form']['input'][] = array(
232+
'type' => 'switch',
233+
'label' => $this->l('Enable Cross-Domain tracking'),
234+
'name' => 'GA_CROSSDOMAIN_ENABLED',
235+
'values' => array(
236+
array(
237+
'id' => 'ga_crossdomain_enabled',
238+
'value' => 1,
239+
'label' => $this->l('Enabled')
240+
),
241+
array(
242+
'id' => 'ga_crossdomain_disabled',
243+
'value' => 0,
244+
'label' => $this->l('Disabled')
245+
)
246+
)
247+
);
248+
}
228249

229250
// Load current value
230251
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
231252
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
253+
$helper->fields_value['GA_CROSSDOMAIN_ENABLED'] = Configuration::get('GA_CROSSDOMAIN_ENABLED');
232254
$helper->fields_value['GA_ANONYMIZE_ENABLED'] = Configuration::get('GA_ANONYMIZE_ENABLED');
233255

234256
return $helper->generateForm($fields_form);
@@ -252,6 +274,13 @@ public function getContent()
252274
Configuration::updateValue('GA_USERID_ENABLED', (bool)$ga_userid_enabled);
253275
$output .= $this->displayConfirmation($this->trans('Settings for User ID updated successfully', array(), 'Modules.GAnalytics.Admin'));
254276
}
277+
278+
$ga_crossdomain_enabled = Tools::getValue('GA_CROSSDOMAIN_ENABLED');
279+
if (null !== $ga_crossdomain_enabled) {
280+
Configuration::updateValue('GA_CROSSDOMAIN_ENABLED', (bool)$ga_crossdomain_enabled);
281+
$output .= $this->displayConfirmation($this->trans('Settings for User ID updated successfully', array(), 'Modules.GAnalytics.Admin'));
282+
}
283+
255284
$ga_anonymize_enabled = Tools::getValue('GA_ANONYMIZE_ENABLED');
256285
if (null !== $ga_anonymize_enabled) {
257286
Configuration::updateValue('GA_ANONYMIZE_ENABLED', (bool)$ga_anonymize_enabled);
@@ -264,36 +293,41 @@ public function getContent()
264293
return $this->display(__FILE__, './views/templates/admin/configuration.tpl').$output;
265294
}
266295

267-
protected function _getGoogleAnalyticsTag($back_office = false)
268-
{
269-
$user_id = null;
270-
if (Configuration::get('GA_USERID_ENABLED') &&
271-
$this->context->customer && $this->context->customer->isLogged()
272-
) {
273-
$user_id = (int)$this->context->customer->id;
274-
}
275-
276-
return '
277-
<script type="text/javascript">
278-
(window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\');
279-
(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
280-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
281-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
282-
})(window,document,\'script\',\'https://www.google-analytics.com/analytics.js\',\'ga\');
283-
ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\');
284-
ga(\'require\', \'ec\');'
285-
.(($user_id && !$back_office) ? 'ga(\'set\', \'userId\', \''.$user_id.'\');': '')
286-
.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '')
287-
.(Configuration::get('GA_ANONYMIZE_ENABLED') ? 'ga(\'set\', \'anonymizeIp\', true);' : '')
288-
.'</script>';
289-
}
290-
291-
public function hookdisplayHeader($params)
296+
public function hookdisplayHeader($params, $back_office = false)
292297
{
293298
if (Configuration::get('GA_ACCOUNT_ID')) {
294299
$this->context->controller->addJs($this->_path.'views/js/GoogleAnalyticActionLib.js');
300+
301+
$shops = Shop::getShops();
302+
$is_multistore_active = Shop::isFeatureActive();
303+
304+
$current_shop_id = (int)Context::getContext()->shop->id;
305+
306+
$user_id = null;
307+
$ga_crossdomain_enabled = false;
308+
309+
if (Configuration::get('GA_USERID_ENABLED') &&
310+
$this->context->customer && $this->context->customer->isLogged()
311+
) {
312+
$user_id = (int)$this->context->customer->id;
313+
}
314+
315+
if ((int)Configuration::get('GA_CROSSDOMAIN_ENABLED') && $is_multistore_active && sizeof($shops) > 1) {
316+
$ga_crossdomain_enabled = true;
317+
}
295318

296-
return $this->_getGoogleAnalyticsTag();
319+
$this->smarty->assign(
320+
array(
321+
'backOffice' => $back_office,
322+
'currentShopId' => $current_shop_id,
323+
'userId' => $user_id,
324+
'gaAccountId' => Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')),
325+
'shops' => $shops,
326+
'gaCrossdomainEnabled' => $ga_crossdomain_enabled,
327+
'useSecureMode' => Configuration::get('PS_SSL_ENABLED')
328+
)
329+
);
330+
return $this->display(__FILE__, 'ps_googleanalytics.tpl');
297331
}
298332
}
299333

@@ -359,7 +393,6 @@ public function hookdisplayFooter()
359393
{
360394
$ga_scripts = '';
361395
$this->js_state = 0;
362-
363396
$gacarts = $this->_manageData("", "R");
364397
if (count($gacarts)>0) {
365398
$this->filterable = 0;
@@ -390,7 +423,6 @@ public function hookdisplayFooter()
390423
$ga_scripts .= 'MBG.addCheckout(\''.(int)$step.'\');';
391424
}
392425

393-
394426
$confirmation_hook_id = (int)Hook::getIdByName('displayOrderConfirmation');
395427
if (isset(Hook::$executed_hooks[$confirmation_hook_id])) {
396428
$this->eligible = 1;
@@ -761,7 +793,7 @@ public function hookdisplayBackOfficeHeader()
761793
}
762794
}
763795
}
764-
return $js.$this->_getGoogleAnalyticsTag(true).$this->_runJs($ga_scripts, 1);
796+
return $js.$this->hookdisplayHeader(null, true).$this->_runJs($ga_scripts, 1);
765797
} else {
766798
return $js;
767799
}

views/templates/hook/index.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* 2007-2015 PrestaShop
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/afl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2015 PrestaShop SA
23+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*/
26+
27+
header('Expires: Mon, 26 Jul 1998 05:00:00 GMT');
28+
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
29+
30+
header('Cache-Control: no-store, no-cache, must-revalidate');
31+
header('Cache-Control: post-check=0, pre-check=0', false);
32+
header('Pragma: no-cache');
33+
34+
header('Location: ../');
35+
exit;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{*
2+
* 2007-2017 PrestaShop
3+
*
4+
* NOTICE OF LICENSE
5+
*
6+
* This source file is subject to the Academic Free License (AFL 3.0)
7+
* that is bundled with this package in the file LICENSE.txt.
8+
* It is also available through the world-wide-web at this URL:
9+
* http://opensource.org/licenses/afl-3.0.php
10+
* If you did not receive a copy of the license and are unable to
11+
* obtain it through the world-wide-web, please send an email
12+
* to license@prestashop.com so we can send you a copy immediately.
13+
*
14+
* DISCLAIMER
15+
*
16+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17+
* versions in the future. If you wish to customize PrestaShop for your
18+
* needs please refer to http://www.prestashop.com for more information.
19+
*
20+
* @author PrestaShop SA <contact@prestashop.com>
21+
* @copyright 2007-2017 PrestaShop SA
22+
* @version Release: $Revision:7040 $
23+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*}
26+
27+
{literal}
28+
<script type="text/javascript">
29+
(window.gaDevIds=window.gaDevIds||[]).push('d6YPbH');
30+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
31+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
32+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
33+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
34+
{/literal}
35+
{if $gaCrossdomainEnabled}
36+
ga('create', '{$gaAccountId|escape:'htmlall':'UTF-8'}', 'auto', {literal}{'allowLinker': true}{/literal});
37+
ga('require', 'linker');
38+
ga('linker:autoLink', [
39+
{foreach from=$shops item=shop}
40+
{if $shop.id_shop != $currentShopId}
41+
{if $useSecureMode}'{$shop.domain_ssl|escape:'htmlall':'UTF-8'}'{else}'{$shop.domain|escape:'htmlall':'UTF-8'}'{/if},
42+
{/if}
43+
{/foreach}
44+
]);
45+
{else}
46+
ga('create', '{$gaAccountId|escape:'htmlall':'UTF-8'}', 'auto');
47+
{/if}
48+
{if $userId && !$backOffice}
49+
ga('set', 'userId', '{$userId|escape:'htmlall':'UTF-8'}');
50+
{/if}
51+
{if $backOffice}
52+
ga('set', 'nonInteraction', true);
53+
{/if}
54+
{literal}
55+
ga('require', 'ec');
56+
</script>
57+
{/literal}

0 commit comments

Comments
 (0)