Skip to content

Commit 59a3ec4

Browse files
Merge pull request #38 from PrestaShop/dev
Release v3.2.0 of Google Analytics module
2 parents ea820dd + a41f865 commit 59a3ec4

3 files changed

Lines changed: 35 additions & 2 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.1.3]]></version>
5+
<version><![CDATA[3.2.0]]></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: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030

3131
class Ps_Googleanalytics extends Module
3232
{
33+
/**
34+
* @var string Name of the module running on PS 1.6.x. Used for data migration.
35+
*/
36+
const PS_16_EQUIVALENT_MODULE = 'ganalytics';
37+
3338
protected $js_state = 0;
3439
protected $eligible = 0;
3540
protected $filterable = 1;
@@ -40,7 +45,7 @@ public function __construct()
4045
{
4146
$this->name = 'ps_googleanalytics';
4247
$this->tab = 'analytics_stats';
43-
$this->version = '3.1.3';
48+
$this->version = '3.2.0';
4449
$this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => _PS_VERSION_);
4550
$this->author = 'PrestaShop';
4651
$this->module_key = 'fd2aaefea84ac1bb512e6f1878d990b8';
@@ -59,6 +64,8 @@ public function install()
5964
Shop::setContext(Shop::CONTEXT_ALL);
6065
}
6166

67+
$this->uninstallPrestaShop16Module();
68+
6269
if (parent::install() &&
6370
$this->registerHook('displayHeader') &&
6471
$this->registerHook('displayAdminOrder') &&
@@ -86,6 +93,30 @@ public function uninstall()
8693
return false;
8794
}
8895

96+
/**
97+
* Migrate data from 1.6 equivalent module (if applicable), then uninstall
98+
*/
99+
public function uninstallPrestaShop16Module()
100+
{
101+
if (!Module::isInstalled(self::PS_16_EQUIVALENT_MODULE)) {
102+
return false;
103+
}
104+
$oldModule = Module::getInstanceByName(self::PS_16_EQUIVALENT_MODULE);
105+
if ($oldModule) {
106+
if (method_exists($oldModule, 'uninstallTab')) {
107+
$oldModule->uninstallTab();
108+
}
109+
// This closure calls the parent class to prevent data to be erased
110+
// It allows the new module to be configured without migration
111+
$parentUninstallClosure = function() {
112+
return parent::uninstall();
113+
};
114+
$parentUninstallClosure = $parentUninstallClosure->bindTo($oldModule, get_class($oldModule));
115+
$parentUninstallClosure();
116+
}
117+
return true;
118+
}
119+
89120
/**
90121
* Creates tables
91122
*/

views/templates/hook/ps_googleanalytics.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
{/if}
5454
{if $backOffice}
5555
ga('set', 'nonInteraction', true);
56+
{else}
57+
ga('send', 'pageview');
5658
{/if}
5759
{literal}
5860
ga('require', 'ec');

0 commit comments

Comments
 (0)