Problem/Motivation

The Commerce integration is opinionated to where the item ids do not match ones we currently use for product feeds and legacy UA ecommerce tracking. We need to be able to alter the tag event data before it's sent to the DOM. There is no built-in method to override the data produced by the tag plugins.

Proposed resolution

Currently I have not found a way to do this without breaking API compatibility, or changing how the attachment hook / response subscriber collects events. See MR for potential new feature.

Remaining tasks

Decide on a path forward for alter events.

User interface changes

None.

API changes

None with MR, but it's dirty.

Data model changes

Attachment hook and response subscriber get a new method for collecting event data.

Issue fork google_tag-3358305

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alexandersluiter created an issue. See original summary.

adebruin’s picture

StatusFileSize
new4.63 KB

This patch takes the original patch and applies it to the latest release (2.0.2)

adebruin’s picture

StatusFileSize
new8.4 KB

There was something missing in the previous patch. Here is the working one

adebruin’s picture

StatusFileSize
new8.3 KB
adebruin’s picture

StatusFileSize
new8.34 KB

timohuisman made their first commit to this issue’s fork.

rszrama’s picture

Assigned: alexandersluiter » Unassigned
Issue tags: +Deprecate Commerce GTM

Not specifically sure the old module supported event level alteration, but it's a good idea and something I'm tagging to make sure we review / help push forward as part of that initiative.

rszrama’s picture

A less invasive solution may be proposed in #3410273: Allow to alter order item data for commerce events; cross-linking here.

berdir’s picture

I didn't see this issue when I worked on mine. What I struggled with in my implementation was making the necessary context available to the event in a useful way. Many of the commerce plugins work in different ways, their context differs and the data they produce differs. My MR focuses on unifying that and having more specific events that work for many different events.

kazajhodo’s picture

StatusFileSize
new8.36 KB

Updated patch for 2.0.5.

kazajhodo’s picture

StatusFileSize
new7.93 KB

Updated patch for 2.0.6.

rob230’s picture

This is working nicely, and a much-needed feature.

Since there is no event name, you have to use the class name. Here's example usage:

In your EventSubscriber:

public static function getSubscribedEvents(): array {
  return [
    OrderItemDataEvent::class => ['onOrderItemEvent'],
  ];
}

public function onOrderItemEvent(OrderItemDataEvent $event): void {
  $itemData = $event->getItemData();
  // Do some things to $itemData here.
   $event->setItemData($itemData);
}
casey’s picture

StatusFileSize
new7.09 KB

Reroll of patch #16 for D11 replacing Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher with Symfony\Component\EventDispatcher\EventDispatcher

https://www.drupal.org/node/3376090