django-plans icon indicating copy to clipboard operation
django-plans copied to clipboard

Add ecomerce tracking to complete order

Open PetrDlouhy opened this issue 5 years ago • 2 comments

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 %}

PetrDlouhy avatar Dec 15 '18 09:12 PetrDlouhy