Skip to content

Commit 109a279

Browse files
committed
[MO] Added multi domain tracking for multistore configurations
1 parent 7052236 commit 109a279

3 files changed

Lines changed: 118 additions & 31 deletions

File tree

ps_googleanalytics.php

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ public function displayForm()
167167
'hint' => $this->l('This information is available in your Google Analytics account')
168168
),
169169
array(
170-
'type' => 'radio',
170+
'type' => 'switch',
171171
'label' => $this->l('Enable User ID tracking'),
172172
'name' => 'GA_USERID_ENABLED',
173-
'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'),
174-
'values' => array(
173+
'values' => array(
175174
array(
176175
'id' => 'ga_userid_enabled',
177176
'value' => 1,
@@ -181,8 +180,7 @@ public function displayForm()
181180
'id' => 'ga_userid_disabled',
182181
'value' => 0,
183182
'label' => $this->l('Disabled')
184-
),
185-
),
183+
))
186184
),
187185
),
188186
'submit' => array(
@@ -222,35 +220,34 @@ public function getContent()
222220
return $this->display(__FILE__, './views/templates/admin/configuration.tpl').$output;
223221
}
224222

225-
protected function _getGoogleAnalyticsTag($back_office = false)
226-
{
227-
$user_id = null;
228-
if (Configuration::get('GA_USERID_ENABLED') &&
229-
$this->context->customer && $this->context->customer->isLogged()
230-
) {
231-
$user_id = (int)$this->context->customer->id;
232-
}
233-
234-
return '
235-
<script type="text/javascript">
236-
(window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\');
237-
(function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
238-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
239-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
240-
})(window,document,\'script\',\'https://www.google-analytics.com/analytics.js\',\'ga\');
241-
ga(\'create\', \''.Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')).'\', \'auto\');
242-
ga(\'require\', \'ec\');'
243-
.(($user_id && !$back_office) ? 'ga(\'set\', \'userId\', \''.$user_id.'\');': '')
244-
.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '')
245-
.'</script>';
246-
}
247223

248-
public function hookdisplayHeader($params)
224+
public function hookdisplayHeader($params, $back_office = false)
249225
{
250226
if (Configuration::get('GA_ACCOUNT_ID')) {
251227
$this->context->controller->addJs($this->_path.'views/js/GoogleAnalyticActionLib.js');
252-
253-
return $this->_getGoogleAnalyticsTag();
228+
229+
$shops = Shop::getShops();
230+
$is_multistore_active = Shop::isFeatureActive();
231+
232+
$user_id = null;
233+
234+
if (Configuration::get('GA_USERID_ENABLED') &&
235+
$this->context->customer && $this->context->customer->isLogged()
236+
) {
237+
$user_id = (int)$this->context->customer->id;
238+
}
239+
240+
241+
$this->smarty->assign(
242+
array(
243+
'backOffice' => $back_office,
244+
'userId' => $user_id,
245+
'gaAccountId' => Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')),
246+
'multiStoreActive' => $is_multistore_active,
247+
'shops' => $shops
248+
)
249+
);
250+
return $this->display(__FILE__, 'ps_googleanalytics.tpl');
254251
}
255252
}
256253

@@ -688,7 +685,7 @@ public function hookdisplayBackOfficeHeader()
688685
}
689686
}
690687
}
691-
return $js.$this->_getGoogleAnalyticsTag(true).$this->_runJs($ga_scripts, 1);
688+
return $js.$this->hookdisplayHeader(null, true).$this->_runJs($ga_scripts, 1);
692689
} else {
693690
return $js;
694691
}

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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 $multiStoreActive}
36+
ga('create', '{$gaAccountId}', 'auto', {literal}{'allowLinker': true}{/literal});
37+
ga('require', 'linker');
38+
ga('linker:autoLink', [
39+
{foreach from=$shops item=shop}
40+
'{if $use_secure_more}{$shop.domain_ssl}{else}{$shop.domain}{/if}',
41+
{/foreach}
42+
]);
43+
{else}
44+
ga('create', '{$gaAccountId}', 'auto');
45+
{/if}
46+
{if $userId && !$backOffice}
47+
ga('set', 'userId', '{$userId}');
48+
{/if}
49+
{if $backOffice}
50+
ga('set', 'nonInteraction', true);
51+
{/if}
52+
{literal}
53+
ga('require', 'ec');
54+
</script>
55+
{/literal}

0 commit comments

Comments
 (0)