Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added queue clearing #170

Open
wants to merge 3 commits 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
9 changes: 9 additions & 0 deletions controllers/front/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ public function initContent()
{
parent::initContent();

if (Tools::getValue('action') === 'flushQueue') {
$output = $this->module->getDataHandler()->readData();

$this->module->getDataHandler()->deleteData();

$this->ajaxRender(json_encode($output));
exit;
}

$orderId = (int) Tools::getValue('orderid');
$order = new Order($orderId);

Expand Down
7 changes: 7 additions & 0 deletions ps_googleanalytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public function getContent()

public function hookDisplayHeader($params, $back_office = false)
{
if ($back_office === false) {
Media::addJsDef([
'psGoogleAnalyticsAjaxUrl' => $this->context->link->getModuleLink($this->name, 'ajax', [], true),
]);
$this->context->controller->registerJavascript('modules-psgoogleanalytics', 'modules/' . $this->name . '/views/js/ganalytics.js');
}

$hook = new PrestaShop\Module\Ps_Googleanalytics\Hooks\HookDisplayHeader($this, $this->context);
$hook->setBackOffice($back_office);

Expand Down
50 changes: 50 additions & 0 deletions views/js/ganalytics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 2007-2020 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (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:
* https://opensource.org/licenses/AFL-3.0
* 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-2020 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

$(document).ready(function () {
prestashop.on('updateCart', flushQueue);
prestashop.on('changedCheckoutStep', flushQueue);
prestashop.on('clickQuickView', flushQueue);
prestashop.on('updatedProduct', flushQueue);
prestashop.on('updateProductList', flushQueue);

function flushQueue() {
$.ajax({
type: "POST",
url: psGoogleAnalyticsAjaxUrl,
dataType: "json",
data: {
ajax: true,
action: "flushQueue",
},
success: function (response) {
response.forEach(code => {
const fn = new Function(code);
fn();
});
}
});
}
});
28 changes: 28 additions & 0 deletions views/js/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* 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.
*
* @author PrestaShop SA <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1998 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');

header('Location: ../');
exit;
Loading