Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

[*] MO: ganalytics anonymizeIp feature added as selectable option #85

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ganalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ public function displayForm()
),
),
),
array(
'type' => 'radio',
'label' => $this->l('Enable AnonymizeIp'),
'name' => 'GA_ANONYMIZEIP_ENABLED',
'hint' => $this->l('If enabled, prevents Google from saving the full IP address for a visitor.'),
'values' => array(
array(
'id' => 'ga_anonymizeip_enabled',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'ga_anonymizeip_disabled',
'value' => 0,
'label' => $this->l('Disabled')
),
),
),
),
'submit' => array(
'title' => $this->l('Save'),
Expand All @@ -206,6 +224,7 @@ public function displayForm()
// Load current value
$helper->fields_value['GA_ACCOUNT_ID'] = Configuration::get('GA_ACCOUNT_ID');
$helper->fields_value['GA_USERID_ENABLED'] = Configuration::get('GA_USERID_ENABLED');
$helper->fields_value['GA_ANONYMIZEIP_ENABLED'] = Configuration::get('GA_ANONYMIZEIP_ENABLED');

return $helper->generateForm($fields_form);
}
Expand All @@ -231,6 +250,12 @@ public function getContent()
Configuration::updateValue('GA_USERID_ENABLED', (bool)$ga_userid_enabled);
$output .= $this->displayConfirmation($this->l('Settings for User ID updated successfully'));
}
$ga_anonymizeip_enabled = Tools::getValue('GA_ANONYMIZEIP_ENABLED');
if (null !== $ga_anonymizeip_enabled)
{
Configuration::updateValue('GA_ANONYMIZEIP_ENABLED', (bool)$ga_anonymizeip_enabled);
$output .= $this->displayConfirmation($this->l('Settings for AnonymizeIp updated successfully'));
}
}

if (version_compare(_PS_VERSION_, '1.5', '>='))
Expand All @@ -249,12 +274,17 @@ public function getContent()
protected function _getGoogleAnalyticsTag($back_office = false)
{
$user_id = null;
$anonymizeip = false;
if (Configuration::get('GA_USERID_ENABLED') &&
$this->context->customer && $this->context->customer->isLogged()
){
$user_id = (int)$this->context->customer->id;
}

if (Configuration::get('GA_ANONYMIZEIP_ENABLED')) {
$anonymizeip = true;
}

return '
<script type="text/javascript">
(window.gaDevIds=window.gaDevIds||[]).push(\'d6YPbH\');
Expand All @@ -266,6 +296,7 @@ protected function _getGoogleAnalyticsTag($back_office = false)
ga(\'require\', \'ec\');'
.(($user_id && !$back_office) ? 'ga(\'set\', \'&uid\', \''.$user_id.'\');': '')
.($back_office ? 'ga(\'set\', \'nonInteraction\', true);' : '')
.($anonymizeip ? 'ga(\'set\', \'anonymizeIp\', true);' : '')
.'</script>';
}

Expand Down
32 changes: 32 additions & 0 deletions upgrade/Upgrade-2.3.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!defined('_PS_VERSION_'))
exit;
function upgrade_module_2_3_4($object)
{
Configuration::updateValue('GA_ANONYMIZEIP_ENABLED', false);
return true;
}