Tracking Coupon codes from Commerce Promotions

Created on 23 April 2024, 8 months ago
Updated 3 May 2024, 8 months ago

Problem/Motivation

Our client has requested the use of Promo codes to assist with a marketing campaign. Great job Drupal Commerce - Promotion module installed, configured and good to go. We now need to understand the efficacy of the campaign - and see the promo codes manifest within our GA4 reports.

Proposed resolution

Implement a further field within the PurchaseEvent Commerce Event:

"coupon": 'SUMMER_SALE'

https://developers.google.com/analytics/devguides/collection/ga4/ecommer...

Use a similar logic as for the tax field - using the adjustment collector to arrive at the promotion label...

$order->collectAdjustments(['promotion']
✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom newaytech

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @newaytech
  • πŸ‡ΊπŸ‡ΈUnited States rszrama

    Drupal Commerce has a coupon reference field on orders that stores which coupons have been applied to the order. It's not an exact match to Google's data model, which appears to expect a single coupon, but we can grab the first one and add it to the purchase event template in:

    https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/src/Plugin/Go...

    Would be nice if one of the options I've tagged into the "Deprecate Commerce GTM" list could be used to give merchants the opportunity to alter which coupon code gets used in the event of there being more than one. We could always sort them by their relative promotion sort orders so there's at least a consistent default with some UI based influence.

  • First commit to issue fork.
  • Status changed to Needs review 8 months ago
  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    I created a MR with simply adding the coupon code to the dataLayer.

  • Pipeline finished with Failed
    8 months ago
    Total: 244s
    #155374
  • πŸ‡¬πŸ‡§United Kingdom newaytech

    Thanks kaszarobert - can I add your commit into my composer.json - or do we need a .patch file for that?

  • πŸ‡ΈπŸ‡°Slovakia kaszarobert

    @newaytech usually you add patch files to composer.json because the feature branch used for MR could change in the meantime if further changes will be required by reviewers. A patch file will stay the same. I uploaded a static patch file with the same modifications as in MR.

  • πŸ‡¬πŸ‡§United Kingdom newaytech

    Thanks kaszarobert - I've applied your patch via composer.json - works a treat - and we're now tracking promo codes in GA4 via GTM - fantastic!

Production build 0.71.5 2024