Browse Source

On redirection, don't show piwik information, but store it on session for use in a user visible page.

tags/0.1.0
Ulrich Van Den Hekke 5 years ago
parent
commit
7c9297a12b

+ 1
- 0
.hgignore View File

@@ -2,3 +2,4 @@ syntax: glob
.settings
.project
.buildpath
nbproject

EventListener/PiwikCustomVariable.php → Common/PiwikCustomVariable.php View File

@@ -9,8 +9,11 @@
* file that was distributed with this source code.
*/

namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* Entry that is used to store custom variable.
*/
class PiwikCustomVariable {
private $name;
private $value;

EventListener/PiwikEcommerceCartUpdate.php → Common/PiwikEcommerceCartUpdate.php View File

@@ -9,8 +9,11 @@
* file that was distributed with this source code.
*/

namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* Amount of a card update.
*/
class PiwikEcommerceCartUpdate {
private $amount;

EventListener/PiwikEcommerceItem.php → Common/PiwikEcommerceItem.php View File

@@ -1,6 +1,9 @@
<?php
namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* E-commerce item.
*/
class PiwikEcommerceItem {
private $productSKU;
private $productName;

EventListener/PiwikEcommerceOrder.php → Common/PiwikEcommerceOrder.php View File

@@ -9,8 +9,11 @@
* file that was distributed with this source code.
*/

namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* Order information to store in piwik.
*/
class PiwikEcommerceOrder {
private $orderId;
private $grandTotal;

EventListener/PiwikEcommerceView.php → Common/PiwikEcommerceView.php View File

@@ -9,8 +9,11 @@
* file that was distributed with this source code.
*/

namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* Represent a piwik e-commerce view.
*/
class PiwikEcommerceView {
private $productSKU;
private $productName;

EventListener/PiwikGoal.php → Common/PiwikGoal.php View File

@@ -1,7 +1,10 @@
<?php

namespace Shadoware\PiwikBundle\EventListener;
namespace Shadoware\PiwikBundle\Common;

/**
* Represent a piwik goal.
*/
class PiwikGoal {
private $id;
private $amount;

+ 158
- 0
Common/PiwikStorage.php View File

@@ -0,0 +1,158 @@
<?php

namespace Shadoware\PiwikBundle\Common;

/**
* Class that will contains the storage of piwik informations.
*/
class PiwikStorage {
protected $trackSiteSearchKeyword = "";
protected $trackSiteSearchCategory = "";
protected $trackSiteSearchCount = false;
protected $customVariables = array();
protected $ecommerceItems = array();
protected $ecommerceView = null;
protected $ecommerceOrder = null;
protected $ecommerceCartUpdate = null;
protected $goals = array();
protected $pageName = null;
protected $pageUrl = null;
/**
* Set the page name.
*/
public function setPageName($pageName) {
$this->pageName = $pageName;
}
/**
* Get the page name.
*/
public function getPageName() {
return $this->pageName;
}
/**
* Set the page URL.
*/
public function setPageUrl($pageUrl) {
$this->pageUrl = $pageUrl;
}
/**
* Return the page URL.
*/
public function getPageUrl() {
return $this->pageUrl;
}
/**
* Set a custom variable.
*/
public function setCustomVariable ($index, $name, $value, $scope = "visit") {
$this->customVariables[$scope][$index] = new PiwikCustomVariable($name, $value);
}
/**
* Delete a defined custom variable.
*/
public function deleteCustomVariable($index, $scope) {
unset($this->customVariables[$scope][$index]);
}
/**
* Get the value of a custom variable.
*/
public function getCustomVariable($index, $scope = "visit") {
return $this->customVariables[$scope][$index];
}
/**
* Return the custom variables.
*/
public function getCustomVariables() {
return $this->customVariables;
}
/**
* Define the track site search attributes.
*/
public function trackSiteSearch($keyword, $category = '', $count = false) {
$this->trackSiteSearchKeyword = $keyword;
$this->trackSiteSearchCategory = $category;
$this->trackSiteSearchCount = $count;
}
/** Get the track site search keyword. */
public function getTrackSiteSearchKeyword() {
return $this->trackSiteSearchKeyword;
}
/** Get the track site search category. */
public function getTrackSiteSearchCategory() {
return $this->trackSiteSearchCategory;
}
/** Get the track site search count. */
public function getTrackSiteSearchCount() {
return $this->trackSiteSearchCount;
}
/** Add an e-commerce item. */
public function addEcommerceItem($productSKU, $productName = null, $productCategory = null, $price = null, $quantity = null) {
$this->ecommerceItems[] = new PiwikEcommerceItem($productSKU, $productName, $productCategory, $price, $quantity);
}
/** Get the e-commerce item. */
public function getEcommerceItems() {
return $this->ecommerceItems;
}
/** Track an e-commerce order. */
public function trackEcommerceOrder($orderId, $grandTotal, $subTotal = null, $tax = null, $shipping = null, $discount = null) {
$this->ecommerceOrder = new PiwikEcommerceOrder($orderId, $grandTotal, $subTotal, $tax, $shipping, $discount);
}
/** Get a track e-commerce order */
public function getEcommerceOrder() {
return $this->ecommerceOrder;
}
/** Track an e-commerce basket. */
public function trackEcommerceCartUpdate($amount) {
$this->ecommerceCartUpdate = new PiwikEcommerceCartUpdate($amount);
}
/** Get a track ecommerce cart update. */
public function getEcommerceCartUpdate() {
return $this->ecommerceCartUpdate;
}
/** set the e-commerce view. */
public function setEcommerceView($productSKU, $productName = null, $categoryName = null, $price = null) {
$this->ecommerceView = new PiwikEcommerceView($productSKU, $productName, $categoryName, $price);
}
/** Get the e-commerce view. */
public function getEcommerceView() {
return $this->ecommerceView;
}
/** Track a goal. */
public function trackGoal($id, $amount = null) {
$this->goals[] = new PiwikGoal($id, $amount);
}
/** Get all goals. */
public function getGoals() {
return $this->goals;
}

public function __toString() {
return serialize($this);
}
}


+ 10
- 11
DependencyInjection/Configuration.php View File

@@ -1,14 +1,14 @@
<?php
/*
* This file is part of the ShadowarePiwikBundle package.
*
* (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This file is part of the ShadowarePiwikBundle package.
*
* (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Shadoware\PiwikBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -31,7 +31,6 @@ class Configuration implements ConfigurationInterface {
->scalarNode('id_site')->isRequired()->cannotBeEmpty()->end()
->scalarNode('hidePiwik')->defaultFalse()->end()
->scalarNode('tokenId')->defaultNull()->end()
->booleanNode('async')->defaultFalse()->end()
->arrayNode('heartbeat')
->children()
->scalarNode('enabled')->defaultFalse()->end()

+ 13
- 14
DependencyInjection/ShadowarePiwikExtension.php View File

@@ -1,14 +1,14 @@
<?php
/*
* This file is part of the ShadowarePiwikBundle package.
*
* (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This file is part of the ShadowarePiwikBundle package.
*
* (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Shadoware\PiwikBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
@@ -35,9 +35,8 @@ class ShadowarePiwikExtension extends Extension {
$container->setParameter('shadoware_piwik.id_site', $config['id_site']);
$container->setParameter('shadoware_piwik.hidePiwik', $config['hidePiwik']);
$container->setParameter('shadoware_piwik.tokenId', $config['tokenId']);
$container->setParameter('shadoware_piwik.async', $config['async']);
$container->setParameter('shadoware_piwik.heartbeat.enabled', $config['heartbeat']['enabled']);
$container->setParameter('shadoware_piwik.heartbeat.minimumVisitLength', $config['heartbeat']['minimumVisitLength']);
$container->setParameter('shadoware_piwik.heartbeat.delay', $config['heartbeat']['delay']);
$container->setParameter('shadoware_piwik.heartbeat.enabled', $config['heartbeat']['enabled']);
$container->setParameter('shadoware_piwik.heartbeat.minimumVisitLength', $config['heartbeat']['minimumVisitLength']);
$container->setParameter('shadoware_piwik.heartbeat.delay', $config['heartbeat']['delay']);
}
}

+ 116
- 111
EventListener/PiwikListener.php View File

@@ -14,104 +14,167 @@ namespace Shadoware\PiwikBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Bundle\TwigBundle\TwigEngine;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Bridge\Monolog\Logger;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Response;

/**
* The class piwik listener is used to receive event that ask to add piwik information to the end of the body.
*
* <p>If the listener, can't store it's information on the current page (due to a lacks of body), the attribute
* must be added to the next page shown.</p>
* <p>For this, the PiwikListener must store all it's attribute in the session and restore it at the next step.</p>
*/
class PiwikListener implements EventSubscriberInterface {
const PIWIK_STORAGE = "PIWIK";
protected $templating;
protected $session;
protected $logger;
protected $piwikUrl;
protected $piwikId;
protected $tokenId;
protected $async;
protected $hidePiwik;

protected $heartbeatEnabled = false;
protected $heartbeatMinimumVisitLength = 15;
protected $heartbeatDelay = 30;
protected $trackSiteSearchKeyword = "";
protected $trackSiteSearchCategory = "";
protected $trackSiteSearchCount = false;
protected $customVariables = array();
protected $ecommerceItems = array();
protected $ecommerceView = null;
protected $ecommerceOrder = null;
protected $ecommerceCartUpdate = null;
protected $goals = array();
protected $pageName = null;
protected $pageUrl = null;
public function __construct(TwigEngine $templating, $piwikUrl, $piwikId, $hidePiwik = false, $tokenId = "", $async = false, $heartbeatEnabled = false, $heartbeatMinimumVisitLength = 15, $heartbeatDelay = 30)
protected $storage;

public function __construct(TwigEngine $templating, Session $session, Logger $logger)
{
$this->templating = $templating;
$this->piwikUrl = $piwikUrl;
$this->piwikId = (integer) $piwikId;
$this->hidePiwik = (Boolean) $hidePiwik;
$this->tokenId = $tokenId;
$this->async = (Boolean) $async;
$this->heartbeatEnabled = $heartbeatEnabled;
$this->heartbeatMinimumVisitLength = $heartbeatMinimumVisitLength;
$this->heartbeatDelay = $heartbeatDelay;
$this->session = $session;
$this->logger = $logger;
$this->storage = $this->session->get(PiwikListener::PIWIK_STORAGE);
$this->logger->info("The session contains the storage: ".$this->storage);
if (! $this->storage instanceof \Shadoware\PiwikBundle\Common\PiwikStorage) {
$this->storage = new \Shadoware\PiwikBundle\Common\PiwikStorage();
}
}
public function getPiwikURL() {
return $this->piwikUrl;
}
public function setPiwikURL($value) {
$this->piwikUrl = $value;
}
public function getPiwikId() {
return $this->piwikId;
}
public function setPiwikId($value) {
$this->piwikId = $value;
}
public function getTokenId() {
return $this->tokenId;
}
public function setTokenId($value) {
$this->tokenId = $value;
}
public function getHidePiwik() {
return $this->hidePiwik;
}
public function setHidePiwik($value) {
$this->hidePiwik = $value;
}
public function setHeartbeatEnabled($value) {
$this->heartbeatEnabled = $value;
}
public function getHeartbeatEnabled() {
return $this->heartbeatEnabled;
}
public function setHeartbeatMinimumVisitLength($value) {
$this->heartbeatMinimumVisitLength = $value;
}
public function getHeartbeatMinimumVisitLenght() {
return $this->heartbeatMinimumVisitLength;
}
public function setHeartbeatDelay($value) {
$this->heartbeatDelay = $value;
}
public function getHeartbeatDelay() {
return $this->heartbeatDelay;
}
public function getStorage() {
return $this->storage;
}
public function setPageName($pageName) {
$this->pageName = $pageName;
$this->storage->setPageName($pageName);
$this->save();
}
public function setPageUrl($pageUrl) {
$this->pageUrl = $pageUrl;
$this->storage->setPageUrl($pageUrl);
$this->save();
}
public function setCustomVariable ($index, $name, $value, $scope = "visit") {
$this->customVariables[$scope][$index] = new PiwikCustomVariable($name, $value);
$this->storage->setCustomVariable($index, $name, $value, $scope);
$this->save();
}
public function deleteCustomVariable($index, $scope) {
unset($this->customVariables[$scope][$index]);
$this->storage->deleteCustomVariable($index, $scope);
$this->save();
}
public function getCustomVariable($index, $scope = "visit") {
return $this->customVariables[$scope][$index];
return $this->storage->getCustomVariable($index, $scope);
}
public function trackSiteSearch($keyword, $category = '', $count = false) {
$this->trackSiteSearchKeyword = $keyword;
$this->trackSiteSearchCategory = $category;
$this->trackSiteSearchCount = $count;
$this->storage->trackSiteSearch($keyword, $category, $count);
$this->save();
}
public function addEcommerceItem($productSKU, $productName = null, $productCategory = null, $price = null, $quantity = null) {
$this->ecommerceItems[] = new PiwikEcommerceItem($productSKU, $productName, $productCategory, $price, $quantity);
$this->storage->addEcommerceItem($productSKU, $productName, $productCategory, $price, $quantity);
$this->save();
}
public function trackEcommerceOrder($orderId, $grandTotal, $subTotal = null, $tax = null, $shipping = null, $discount = null) {
$this->ecommerceOrder = new PiwikEcommerceOrder($orderId, $grandTotal, $subTotal, $tax, $shipping, $discount);
$this->storage->trackEcommerceOrder($orderId, $grandTotal, $subTotal, $tax, $shipping, $discount);
$this->save();
}
public function trackEcommerceCartUpdate($amount) {
$this->ecommerceCartUpdate = new PiwikEcommerceCartUpdate($amount);
$this->storage->trackEcommerceCartUpdate($amount);
$this->save();
}
public function setEcommerceView($productSKU, $productName = null, $categoryName = null, $price = null) {
$this->ecommerceView = new PiwikEcommerceView($productSKU, $productName, $categoryName, $price);
$this->storage->setEcommerceView($productSKU, $productName, $categoryName, $price);
$this->save();
}
public function trackGoal($id, $amount = null) {
$this->goals[] = new PiwikGoal($id, $amount);
$this->storage->trackGoal($id, $amount);
$this->save();
}
private function save() {
$this->logger->info("Save the storage in the session: ".$this->storage);
$this->session->set(PiwikListener::PIWIK_STORAGE, $this->storage);
}
public function onKernelResponse(FilterResponseEvent $event)
@@ -124,7 +187,7 @@ class PiwikListener implements EventSubscriberInterface {
$request = $event->getRequest();
// do not capture redirects or modify XML HTTP Requests
if ($request->isXmlHttpRequest()) {
if ($request->isXmlHttpRequest() || $response->isRedirection()) {
return;
}
@@ -145,82 +208,24 @@ class PiwikListener implements EventSubscriberInterface {
$posEndHead = $posrFunction($content, '</head>');
if (false !== $posEndHead) {
if ($this->async == true) {
$piwik_js = "\n".str_replace("\n", '', $this->templating->render(
'ShadowarePiwikBundle:Default:async_piwik_js.html.twig',
array(
'url' => $this->piwikUrl,
'id_site' => $this->piwikId,
'heartbeatEnabled' => $this->heartbeatEnabled,
'heartbeatMinimumVisitLength' => $this->heartbeatMinimumVisitLength,
'heartbeatDelay' => $this->heartbeatDelay,
'customVariables' => $this->customVariables,
'trackSiteSearchKeyword' => $this->trackSiteSearchKeyword,
'trackSiteSearchCategory' => $this->trackSiteSearchCategory,
'trackSiteSearchCount' => $this->trackSiteSearchCount,
'ecommerceView' => $this->ecommerceView,
'ecommerceItems' => $this->ecommerceItems,
'ecommerceOrder' => $this->ecommerceOrder,
'ecommerceCartUpdate' => $this->ecommerceCartUpdate,
'goals' => $this->goals,
'hidePiwik' => $this->hidePiwik,
'pageName' => $this->pageName,
'pageUrl' => $this->pageUrl
)
))."\n";
}
else {
$piwik_js = "";
}
$piwik_js = "\n".str_replace("\n", '', $this->templating->render(
'ShadowarePiwikBundle:Default:async_piwik_js.html.twig',
array(
'url' => $this->piwikUrl,
'id_site' => $this->piwikId,
'heartbeatEnabled' => $this->heartbeatEnabled,
'heartbeatMinimumVisitLength' => $this->heartbeatMinimumVisitLength,
'heartbeatDelay' => $this->heartbeatDelay,
'hidePiwik' => $this->hidePiwik,
'storage' => $this->storage
)
))."\n";

$content = $substrFunction($content, 0, $posEndHead).$piwik_js.$substrFunction($content, $posEndHead);
$response->setContent($content);
}
$posEndBody = $posrFunction($content, '</body>');
if (false !== $posEndBody) {
if ($this->async == false) {
$piwik_js = "\n".str_replace("\n", '', $this->templating->render(
'ShadowarePiwikBundle:Default:sync_piwik_js.html.twig',
array(
'url' => $this->piwikUrl,
'id_site' => $this->piwikId,
'heartbeatEnabled' => $this->heartbeatEnabled,
'heartbeatMinimumVisitLength' => $this->heartbeatMinimumVisitLength,
'heartbeatDelay' => $this->heartbeatDelay,
'customVariables' => $this->customVariables,
'trackSiteSearchKeyword' => $this->trackSiteSearchKeyword,
'trackSiteSearchCategory' => $this->trackSiteSearchCategory,
'trackSiteSearchCount' => $this->trackSiteSearchCount,
'ecommerceView' => $this->ecommerceView,
'ecommerceItems' => $this->ecommerceItems,
'ecommerceOrder' => $this->ecommerceOrder,
'ecommerceCartUpdate' => $this->ecommerceCartUpdate,
'goals' => $this->goals,
'hidePiwik' => $this->hidePiwik,
'pageName' => $this->pageName,
'pageUrl' => $this->pageUrl
)
))."\n";
}
else {
$piwik_js = "";
}
if (! $this->hidePiwik) {
$piwik_nojs = "\n".str_replace("\n", '', $this->templating->render(
'ShadowarePiwikBundle:Default:piwik_nojs.html.twig',
array(
'url' => $this->piwikUrl,
'id_site' => $this->piwikId,
)
))."\n";
}
else {
$piwik_nojs = "";
}
$content = $substrFunction($content, 0, $posEndBody).$piwik_js.$piwik_nojs.$substrFunction($content, $posEndBody);
$response->setContent($content);
$this->logger->info("Remove the piwik from the storage.");
$this->session->remove(PiwikListener::PIWIK_STORAGE);
}
}

+ 23
- 8
Resources/config/services.xml View File

@@ -22,14 +22,29 @@
<service id="shadoware_piwik.service" class="%shadoware_piwik.service.class%" >
<tag name="kernel.event_subscriber" />
<argument type="service" id="templating.engine.twig" />
<argument>%shadoware_piwik.base_url%</argument>
<argument>%shadoware_piwik.id_site%</argument>
<argument>%shadoware_piwik.hidePiwik%</argument>
<argument>%shadoware_piwik.tokenId%</argument>
<argument>%shadoware_piwik.async%</argument>
<argument>%shadoware_piwik.heartbeat.enabled%</argument>
<argument>%shadoware_piwik.heartbeat.minimumVisitLength%</argument>
<argument>%shadoware_piwik.heartbeat.delay%</argument>
<argument type="service" id="session" />
<argument type="service" id="logger" />
<call method="setPiwikURL">
<argument>%shadoware_piwik.base_url%</argument>
</call>
<call method="setPiwikId">
<argument>%shadoware_piwik.id_site%</argument>
</call>
<call method="setHidePiwik">
<argument>%shadoware_piwik.hidePiwik%</argument>
</call>
<call method="setTokenId">
<argument>%shadoware_piwik.tokenId%</argument>
</call>
<call method="setHeartbeatEnabled">
<argument>%shadoware_piwik.heartbeat.enabled%</argument>
</call>
<call method="setHeartbeatMinimumVisitLength">
<argument>%shadoware_piwik.heartbeat.minimumVisitLength%</argument>
</call>
<call method="setHeartbeatDelay">
<argument>%shadoware_piwik.heartbeat.delay%</argument>
</call>
</service>
<service id="shadoware_piwik.twig" class="%shadoware_piwik.twig.class%">
<tag name="twig.extension"/>

+ 23
- 23
Resources/views/Default/async_piwik_js.html.twig View File

@@ -24,39 +24,39 @@ _paq.push(['setHeartBeatTimer', {{ heartbeatMinimumVisitLength }}, {{ heartbeatD
{% endif %}

{# Custom variables #}
{% for scope, array in customVariables %}
{% for scope, array in storage.customVariables %}
{% for index, customVariable in array %}
_paq.push(['setCustomVariable', {{ index }}, '{{ customVariable.name | e('js') }}', '{{ customVariable.value | e('js') }}', '{{ scope }}']);
{% endfor %}
{% endfor %}

{# Redefine page name #}
{% if pageName %}
_paq.push(['setDocumentTitle', '{{ pageName | e('js') }}']);
{% if storage.pageName %}
_paq.push(['setDocumentTitle', '{{ storage.pageName | e('js') }}']);
{% endif %}

{# Redefine page url #}
{% if pageUrl %}
_paq.push(['setCustomUrl', '{{ pageUrl | e('js') }}']);
{% if storage.pageUrl %}
_paq.push(['setCustomUrl', '{{ storage.pageUrl | e('js') }}']);
{% endif %}

{# Search keyword #}
{% if not trackSiteSearchKeyword is empty %}
_paq.push(['trackSiteSearch', '{{ trackSiteSearchKeyword | e('js') }}', '{{ trackSiteSearchCategory | e('js') }}', {% if not trackSiteSearchCount %}false{% else %}{{ trackSiteSearchCount }}{% endif %}]);
{% if not storage.trackSiteSearchKeyword is empty %}
_paq.push(['trackSiteSearch', '{{ storage.trackSiteSearchKeyword | e('js') }}', '{{ storage.trackSiteSearchCategory | e('js') }}', {% if not storage.trackSiteSearchCount %}false{% else %}{{ storage.trackSiteSearchCount }}{% endif %}]);
{% endif %}

{# E-Commerce - View #}
{% if ecommerceView %}
{% if storage.ecommerceView %}
_paq.push(['setEcommerceView',
{% if not ecommerceView.productSKU %}false{% else %}'{{ ecommerceView.productSKU | e('js') }}'{% endif %},
{% if not ecommerceView.productName %}false{% else %}'{{ ecommerceView.productName | e('js') }}'{% endif %},
{% if not ecommerceView.productCategory %}''{% else %}'{{ ecommerceView.productCategory | e('js') }}'{% endif %}
{% if ecommerceView.productPrice %},{{ ecommerceView.productPrice }}{% endif %}
{% if not storage.ecommerceView.productSKU %}false{% else %}'{{ storage.ecommerceView.productSKU | e('js') }}'{% endif %},
{% if not storage.ecommerceView.productName %}false{% else %}'{{ storage.ecommerceView.productName | e('js') }}'{% endif %},
{% if not storage.ecommerceView.productCategory %}''{% else %}'{{ storage.ecommerceView.productCategory | e('js') }}'{% endif %}
{% if storage.ecommerceView.productPrice %},{{ storage.ecommerceView.productPrice }}{% endif %}
]);
{% endif %}

{# E-Commerce - Items #}
{% for item in ecommerceItems %}
{% for item in storage.ecommerceItems %}
_paq.push(['addEcommerceItem',
'{{ item.productSKU }}',
{% if not item.productName %}''{% else %}'{{ item.productName | e('js') }}'{% endif %},
@@ -67,26 +67,26 @@ _paq.push(['addEcommerceItem',
{% endfor %}

{# E-Commerce - Final order #}
{% if ecommerceOrder and ecommerceItems | length > 0 %}
{% if storage.ecommerceOrder and storage.ecommerceItems | length > 0 %}
_paq.push(['trackEcommerceOrder',
'{{ ecommerceOrder.orderId }}',
{{ ecommerceOrder.grandTotal }},
{% if ecommerceOrder.subTotal %}{{ ecommerceOrder.subTotal }}{% else %}''{% endif %},
{% if ecommerceOrder.tax %}{{ ecommerceOrder.tax }}{% else %}''{% endif %},
{% if ecommerceOrder.shipping %}{{ ecommerceOrder.shipping }}{% else %}''{% endif %},
{% if ecommerceOrder.discount %}{{ ecommerceOrder.discount }}{% else %}false{% endif %}
'{{ storage.ecommerceOrder.orderId }}',
{{ storage.ecommerceOrder.grandTotal }},
{% if storage.ecommerceOrder.subTotal %}{{ storage.ecommerceOrder.subTotal }}{% else %}''{% endif %},
{% if storage.ecommerceOrder.tax %}{{ storage.ecommerceOrder.tax }}{% else %}''{% endif %},
{% if storage.ecommerceOrder.shipping %}{{ storage.ecommerceOrder.shipping }}{% else %}''{% endif %},
{% if storage.ecommerceOrder.discount %}{{ storage.ecommerceOrder.discount }}{% else %}false{% endif %}
]);
{% endif %}

{# E-Commerce - Basket #}
{% if ecommerceCartUpdate and ecommerceItems | length > 0 %}
{% if storage.ecommerceCartUpdate and storage.ecommerceItems | length > 0 %}
_paq.push(['trackEcommerceCartUpdate',
{{ ecommerceCartUpdate.amount }}
{{ storage.ecommerceCartUpdate.amount }}
]);
{% endif %}

{# Goals #}
{% for goal in goals %}
{% for goal in storage.goals %}
_paq.push(['trackGoal', {{ goal.id }}{% if goal.amount %}, {{ goal.amount }}{% endif %}]);
{% endfor %}


+ 0
- 9
Resources/views/Default/piwik_nojs.html.twig View File

@@ -1,9 +0,0 @@
{#
# This file is part of the ShadowarePiwikBundle package.
#
# (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#}
<noscript><p><img src="http://{{ url }}/piwik.php?idsite={{ id_site }}" style="border:0" alt="" /></p></noscript>

+ 0
- 110
Resources/views/Default/sync_piwik_js.html.twig View File

@@ -1,110 +0,0 @@
{#
# This file is part of the ShadowarePiwikBundle package.
#
# (c) Ulrich VANDENHEKKE <ulrich.vdh@shadoware.org>
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#}
{% spaceless %}
<!-- Piwik -->
{# Definition of the Piwik script #}
<script type="text/javascript">/*<![CDATA[*/
{% if not hidePiwik %}
var pkBaseURL = (("https:" == document.location.protocol) ? "https://{{ url }}/" : "http://{{ url }}/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
{% else %}
document.write(unescape("%3Cscript src='{{ url('shadoware_piwik_default_tracker', {'_format': 'js'}) }}' type='text/javascript'%3E%3C/script%3E"));
{% endif %}
/*]]>*/</script>
{# Tracking the page #}
<script type="text/javascript">/*<![CDATA[*/
try {
{# Piwik Tracker #}
{% if not hidePiwik %}
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {{ id_site }});
{% else %}
var piwikTracker = Piwik.getTracker("{{ url('shadoware_piwik_default_track') }}", {{ id_site }});
{% endif %}

{# Heartbeat #}
{% if heartbeatEnabled %}
piwikTracker.setHeartBeatTimer({{ heartbeatMinimumVisitLength }}, {{ heartbeatDelay }});
{% endif %}

{# Custom variables #}
{% for scope, array in customVariables %}
{% for index, customVariable in array %}
piwikTracker.setCustomVariable({{ index }}, '{{ customVariable.name | e('js') }}', '{{ customVariable.value | e('js') }}', '{{ scope }}');
{% endfor %}
{% endfor %}

{# Search keyword #}
{% if not trackSiteSearchKeyword is empty %}
piwikTracker.trackSiteSearch('{{ trackSiteSearchKeyword | e('js') }}', '{{ trackSiteSearchCategory | e('js') }}', {% if not trackSiteSearchCount %}false{% else %}{{ trackSiteSearchCount }}{% endif %});
{% endif %}

{# Redefine page name #}
{% if pageName %}
piwikTracker.setDocumentTitle('{{ pageName | e('js') }}');
{% endif %}

{# Redefine page url #}
{% if pageUrl %}
piwikTracker.setCustomUrl('{{ pageUrl | e('js') }}');
{% endif %}

{# E-Commerce - View #}
{% if ecommerceView %}
piwikTracker.setEcommerceView(
{% if not ecommerceView.productSKU %}false{% else %}'{{ ecommerceView.productSKU | e('js') }}'{% endif %},
{% if not ecommerceView.productName %}false{% else %}'{{ ecommerceView.productName | e('js') }}'{% endif %},
{% if not ecommerceView.productCategory %}''{% else %}'{{ ecommerceView.productCategory | e('js') }}'{% endif %}
{% if ecommerceView.productPrice %},{{ ecommerceView.productPrice }}{% endif %}
);
{% endif %}

{# E-Commerce - Items #}
{% for item in ecommerceItems %}
piwikTracker.addEcommerceItem(
'{{ item.productSKU }}',
{% if not item.productName %}''{% else %}'{{ item.productName | e('js') }}'{% endif %},
{% if not item.productCategory %}''{% else %}'{{ item.productCategory | e('js') }}'{% endif %},
{% if not item.price %}''{% else %}{{ item.price }}{% endif %}
{% if item.quantity %},{{ item.quantity }}{% endif %}
);
{% endfor %}

{# E-Commerce - Final order #}
{% if ecommerceOrder and ecommerceItems | length > 0 %}
piwikTracker.trackEcommerceOrder(
'{{ ecommerceOrder.orderId }}',
{{ ecommerceOrder.grandTotal }},
{% if ecommerceOrder.subTotal %}{{ ecommerceOrder.subTotal }}{% else %}''{% endif %},
{% if ecommerceOrder.tax %}{{ ecommerceOrder.tax }}{% else %}''{% endif %},
{% if ecommerceOrder.shipping %}{{ ecommerceOrder.shipping }}{% else %}''{% endif %},
{% if ecommerceOrder.discount %}{{ ecommerceOrder.discount }}{% else %}false{% endif %}
);
{% endif %}

{# E-Commerce - Basket #}
{% if ecommerceCartUpdate and ecommerceItems | length > 0 %}
piwikTracker.trackEcommerceCartUpdate(
{{ ecommerceCartUpdate.amount }}
);
{% endif %}

{# Goals #}
{% for goal in goals %}
piwikTracker.trackGoal({{ goal.id }}{% if goal.amount %}, {{ goal.amount }}{% endif %});
{% endfor %}

{# Enable link tracking #}
piwikTracker.enableLinkTracking();

{# Really track the page #}
piwikTracker.trackPageView();
} catch( err ) {}
/*]]>*/</script>
<!-- End Piwik Tracking Code -->
{% endspaceless %}

Loading…
Cancel
Save