django-plans
django-plans copied to clipboard
Add ecomerce tracking to complete order
I wanted to set up ecomerce tracking for Google Analytics for my plans. All I had to do is override the plans/order_detail.html
template with the following code. Do you have interest to include this in this project?
{% extends "plans/order_detail.html" %}
{% load i18n %}
{% block head %}
{% if object.get_status_display == 'completed' %}
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'transactionId': '{{ object.id }}',
'transactionTotal': {{ object.total }},
'transactionTax': {{ object.tax_total }},
'transactionProducts': [{
'sku': 'P{{ object.plan.id }}',
'name': '{{ object.name }}',
'price': {{ object.amount }},
'quantity': 1
}]
});
</script>
{% endif %}
{{ block.super }}
{% endblock %}