Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Google Analytics Code for Tracking Purchases #224

Open
stephenmcd opened this issue Jan 5, 2015 · 2 comments
Open

Update Google Analytics Code for Tracking Purchases #224

stephenmcd opened this issue Jan 5, 2015 · 2 comments

Comments

@stephenmcd
Copy link
Owner

As per stephenmcd/mezzanine#1191

@sjdines
Copy link

sjdines commented Feb 5, 2015

The ecommerce code that lives in cartridge.shop.templates.shop.complete.html would be replaced with something like the following:

ga('require', 'ecommerce');     // Load the ecomerce plug-in.

// Add transaction data.
ga('ecommerce:addTransaction', {
    // Order (Transaction) ID. [required]
    'id': '{{ order.id }}',
    // Affiliation or store name
    'affiliation': '',
    // Grand Total [required]
    'revenue': decimal({{ order.item_total }}{% if order.discount_total %} - {{ order.discount_total }}{% endif %}),
    // Shipping
    'shipping': decimal({{ order.shipping_total }}),
    // Tax
    'tax': decimal({% if order.tax_total %}{{ order.tax_total }}{% else %}0{% endif %})
});

// Add item data for each item.
{% for item in items %}
ga('ecommerce:addItem', {
    // Order (Transaction) ID. [Required]
    'id': '{{ order.id }}',
    // Product name. [Required]
    'name': '{{ item.name|escapejs }}',
    // SKU/code
    'sku': '{{ item.sku }}',
    // Category or variation
    'category': '{{ item.description|escapejs }}',
    // Unit price
    'price': decimal({{ item.unit_price }}),
    // Quantity
    'quantity': '{{ item.quantity }}'
});
{% endfor %}

// submits transaction to the Analytics servers
ga('ecommerce:send');

The ga('require', 'ecommerce'); call needs to come after the tracker object creation (and before the ecommerce specific functionality).

As the tracker object creation occurs in mezzanine.core.templates.includes.footer_scripts.html which is included in the base template without a surrounding block tag would you suggest creating the block tag for footer script in the mezzanine project which could be targeted, customising the shop base html moving the tracker object creation to before the ecommerce calls, or something else I have not thought of?

@stephenmcd
Copy link
Owner Author

Excellent, thanks Stuart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants