Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add ecommerce code tracker

Michal Ociepka3f602f4b8512
diff --git a/order/templates/order/success.html b/order/templates/order/success.html
index 3f1654ec31..1cc21b8b58 100644
--- a/order/templates/order/success.html
+++ b/order/templates/order/success.html
@@ -1,10 +1,36 @@
{% extends "base.html" %}
+{% load gross from prices %}
+
{% block content %}
<h2>Your order has been received</h2>
<p>
- <strong>Thank you for your purchase!</strong><br />
+ <strong>Thank you for your purchase!</strong>
+ <br />
Your order # is: <a href="{% url 'order:details' token=order.token %}">{{ order.id }}</a>.
</p>
{% endblock content %}
+{% block google-analytics-script %}
+ {{ block.super }}
+ __ga('require', 'ecommerce', 'ecommerce.js');
+ __ga('set', 'currencyCode', '{{ DEFAULT_CURRENCY }}');
+ __ga('ecommerce:addTransaction', {
+ 'id': '{{ order.id }}',
+ 'affiliation': 'Saleor',
+ 'revenue': '{{ order.get_total.gross }}',
+ 'shipping': '{{ order.get_delivery_total.gross }}',
+ 'tax': '{{ order.get_total.tax }}
+ });
+ {% for item in order.get_items %}
+ __ga('ecommerce:addItem', {
+ 'id': '{{ item.id }}',
+ 'name': '{{ item }}',
+ 'sku': '{{ item.id }}',
+ 'category': '{{ item.product.category }}',
+ 'price': '{{ item.unit_price_gross }}',
+ 'quantity': '{{ item.quantity }}'
+ });
+ {% endfor %}
+ __ga('ecommerce:send');
+{% endblock google-analytics-script %}
diff --git a/saleor/templates/base.html b/saleor/templates/base.html
index f61efd2785..dd6beb7258 100644
--- a/saleor/templates/base.html
+++ b/saleor/templates/base.html
@@ -114,19 +114,21 @@
</p>
</footer>
</div>
- {% block analytics %}
+ {% block third-party-js %}
{% if GOOGLE_ANALYTICS_CODE %}
<script>
+ {% block google-analytics-script %}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
- })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ })(window,document,'script','//www.google-analytics.com/analytics.js','__ga');
- ga('create', '{{ GOOGLE_ANALYTICS_CODE }}', '{{ CANONICAL_HOSTNAME }}');
- ga('send', 'pageview');
+ __ga('create', '{{ GOOGLE_ANALYTICS_CODE }}', '{{ CANONICAL_HOSTNAME }}');
+ __ga('send', 'pageview');
+ {% endblock google-analytics-script %}
</script>
{% endif %}
- {% endblock analytics %}
+ {% endblock third-party-js %}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//twitter.github.com/bootstrap/assets/js/bootstrap-dropdown.js"></script>
</body>