6 changed files with 237 additions and 29 deletions
@ -0,0 +1,136 @@
@@ -0,0 +1,136 @@
|
||||
{# |
||||
# This file is part of the ShadowareMatomoBundle 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 %} |
||||
<!-- Matomo Tag Manager --> |
||||
<script type="text/javascript">/*<![CDATA[*/ |
||||
var _mtm = window._mtm = window._mtm || []; |
||||
{# Matomo user #} |
||||
{% if storage.matomoUser %} |
||||
_mtm.push({'username': '{{ storage.matomoUser }}' }); |
||||
{% endif %} |
||||
|
||||
{# Data #} |
||||
{% for scope, value in variables %} |
||||
_mtm.push({'{{ value.key | e('js') }}': '{{ value.value | raw }}' }); |
||||
{% endfor %} |
||||
|
||||
{# Custom variables #} |
||||
{% for scope, array in storage.customVariables %} |
||||
{% for index, customVariable in array %} |
||||
_mtm.push({'{{ customVariable.name | e('js') }}': '{{ customVariable.value | raw }}' }); |
||||
{% endfor %} |
||||
{% endfor %} |
||||
|
||||
{# Redefine page name #} |
||||
{% if storage.pageName %} |
||||
_mtm.push({'title': '{{ storage.pageName | e('js') }}' }); |
||||
{% endif %} |
||||
|
||||
{# Redefine page url #} |
||||
{% if storage.pageUrl %} |
||||
_mtm.push({'url': '{{ storage.pageUrl | e('js') }}' }); |
||||
{% endif %} |
||||
|
||||
{# Search keyword #} |
||||
{% if not storage.trackSiteSearchKeyword is empty %} |
||||
_mtm.push({ |
||||
'event': 'search', |
||||
'search': { |
||||
'keyword': '{{ storage.trackSiteSearchKeyword | e('js') }}', |
||||
'category': '{{ storage.trackSiteSearchCategory | e('js') }}', |
||||
'count': {% if not storage.trackSiteSearchCount %}false{% else %}{{ storage.trackSiteSearchCount }}{% endif %} |
||||
} |
||||
}); |
||||
{% endif %} |
||||
|
||||
{# E-Commerce - View #} |
||||
{% if storage.ecommerceView %} |
||||
window._mtm.push({ |
||||
'event': 'view', |
||||
'ecommerce': { |
||||
'product': { |
||||
'sku': {% if not storage.ecommerceView.productSKU %}false{% else %}'{{ storage.ecommerceView.productSKU | e('js') }}'{% endif %}, |
||||
'name': {% if not storage.ecommerceView.productName %}false{% else %}'{{ storage.ecommerceView.productName | e('js') }}'{% endif %}, |
||||
'category': {% if not storage.ecommerceView.productCategory %}''{% else %}'{{ storage.ecommerceView.productCategory | e('js') }}'{% endif %} |
||||
'price': {% if storage.ecommerceView.productPrice %},{{ storage.ecommerceView.productPrice }}{% endif %} |
||||
} |
||||
} |
||||
}); |
||||
{% endif %} |
||||
|
||||
{# E-Commerce - Items #} |
||||
{% if storage.ecommerceView | length > 0 %} |
||||
window._mtm.push({ |
||||
'event': 'addItem', |
||||
'ecommerce': { |
||||
'products': [ |
||||
{% for item in storage.ecommerceItems %} |
||||
{ |
||||
'sku': '{{ item.productSKU }}', |
||||
'name': {% if not item.productName %}''{% else %}'{{ item.productName | e('js') }}'{% endif %}, |
||||
'category': {% if not item.productCategory %}''{% else %}'{{ item.productCategory | e('js') }}'{% endif %}, |
||||
'price': {% if not item.price %}''{% else %}{{ item.price }}{% endif %} |
||||
'quantity': {% if item.quantity %},{{ item.quantity }}{% endif %} |
||||
}, |
||||
{% endfor %} |
||||
] |
||||
} |
||||
}); |
||||
{% endif %} |
||||
|
||||
{# E-Commerce - Final order #} |
||||
{% if storage.ecommerceOrder and storage.ecommerceItems | length > 0 %} |
||||
window._mtm.push({ |
||||
'event': 'purchase', |
||||
'ecommerce': { |
||||
'purchase': { |
||||
'id': '{{ storage.ecommerceOrder.orderId }}', |
||||
'revenue': {{ storage.ecommerceOrder.grandTotal }}, |
||||
'orderSubTotal': {% if storage.ecommerceOrder.subTotal %}{{ storage.ecommerceOrder.subTotal }}{% else %}''{% endif %}, |
||||
'tax': {% if storage.ecommerceOrder.tax %}{{ storage.ecommerceOrder.tax }}{% else %}''{% endif %}, |
||||
'shipping': {% if storage.ecommerceOrder.shipping %}{{ storage.ecommerceOrder.shipping }}{% else %}''{% endif %}, |
||||
'discount': {% if storage.ecommerceOrder.discount %}{{ storage.ecommerceOrder.discount }}{% else %}false{% endif %}, |
||||
} |
||||
} |
||||
}); |
||||
{% endif %} |
||||
|
||||
{# E-Commerce - Basket #} |
||||
{% if storage.ecommerceCartUpdate and storage.ecommerceItems | length > 0 %} |
||||
window._mtm.push({ |
||||
'event': 'cartUpdate', |
||||
'ecommerce': { |
||||
'update': { |
||||
'revenue': {{ storage.ecommerceCartUpdate.amount }}, |
||||
} |
||||
} |
||||
}); |
||||
{% endif %} |
||||
|
||||
{# Goals #} |
||||
{% for goal in storage.goals %} |
||||
window._mtm.push({ |
||||
'event': 'trackGoal', |
||||
'goal': { |
||||
'id': {{ goal.id }}, |
||||
'amount': {% if goal.amount %}, {{ goal.amount }}{% endif %}, |
||||
} |
||||
}); |
||||
{% endfor %} |
||||
|
||||
(function(){ |
||||
var u="//{{ url }}/"; |
||||
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}); |
||||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
||||
g.type='text/javascript'; g.async=true; g.src=u+'container_{{ idContainer }}.js'; s.parentNode.insertBefore(g,s); |
||||
})(); |
||||
|
||||
/*]]>*/</script> |
||||
<!-- End Matomo Tag Manager --> |
||||
{% endspaceless %} |
Loading…
Reference in new issue