Problem/Motivation

Was researching how to do this until I found this module, one difference I found from the docs was the structure of the transaction.

The docs point to doing it this way with an actionField:
https://developers.google.com/tag-manager/enhanced-ecommerce#purchases

dataLayer.push({
  'ecommerce': {
    'currencyCode': 'USD',
    'purchase': {
      'actionField': {
        'id': 'ORDERNUMBER',
        'revenue': '32.00',
        'tax':'0',
        'shipping': '0',
        'coupon': 'FREESHIPPING'
      },
      'products': [
        {
          'name': 'Masque',
          'id': 'SKU',
          'price': '32.00',
          'category': 'Masques',
          'variant': 'Retail',
          'quantity': 1
        }
      ]
    }
  }
});

Proposed resolution

Wondering if it should change or maybe a checkbox to toggle between the two. FWIU it may be related to that "enhanced ecommerce" bit.

Remaining tasks

  1. Create patch
  2. Review patch
  3. Commit

User interface changes

API changes

Data model changes

Comments

joelpittet’s picture

Title: GTM data format » Allow Enhanced Ecommerce format
Issue summary: View changes
joelpittet’s picture

Status: Active » Needs review
StatusFileSize
new5.44 KB

Here's what I was thinking. Let me know if this is something you'd be keen on including in your module or not?

joelpittet’s picture

StatusFileSize
new5.44 KB

Whoops a typo in that one, ; vs ,

joelpittet’s picture

This should be good now;)

parisek’s picture

StatusFileSize
new6.69 KB
new103.41 KB

joelpittet: Thank you for your contribution, I made few changes to better inform administration users about configuration possibilities, please review.

joelpittet’s picture

StatusFileSize
new4.25 KB

Here is an interdiff between the two help review the changes.
@see https://www.drupal.org/documentation/git/interdiff

joelpittet’s picture

+++ b/commerce_google_tag_manager.module
@@ -97,11 +96,11 @@ function commerce_google_tag_manager_ecommerce_js($order) {
-  $order_number = $order->order_number->value() ?: $order_id;
+  $order_number = $order->order_number->value() ? $order->order_number->value() : $order_id;

Personal preference?

These changes look good:) THanks

parisek’s picture

Sorry I forgot interdiff :)

I don't know this shorthand version of ternary operator, but it's PHP 5.3+ thing and Drupal 7 requirement is PHP 5.2.5 or higher so I keep it old way.

  • parisek committed 4fd63d4 on 7.x-1.x authored by joelpittet
    Issue #2529278 by joelpittet, parisek: Allow Enhanced Ecommerce format
    
parisek’s picture

Status: Needs review » Fixed
joelpittet’s picture

Oh yeah people still care about 5.2 :D

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.