You are here

public function EventStorageService::addEvent in Commerce Google Tag Manager 8.2

Same name and namespace in other branches
  1. 8 src/EventStorageService.php \Drupal\commerce_google_tag_manager\EventStorageService::addEvent()

Add event data to the storage.

Computes a hash from the given event data to prevent storing the exact same event multiple times.

Parameters

array $event_data: The event data to store.

Return value

$this Return the EventStorageService object.

File

src/EventStorageService.php, line 69

Class

EventStorageService
Stores all tracked Enhanced Ecommerce events in a private tempstore.

Namespace

Drupal\commerce_google_tag_manager

Code

public function addEvent(array $event_data) {
  $events = (array) $this->tempStore
    ->get('events') ?: [];
  $hash = $this
    ->hash($event_data);
  if (!isset($events[$hash])) {
    $event = new AlterEventDataEvent($event_data);
    $this->eventDispatcher
      ->dispatch(EnhancedEcommerceEvents::ALTER_EVENT_DATA, $event);
    $events[$this
      ->hash($event_data)] = $event
      ->getEventData();
    $this->tempStore
      ->set('events', $events);
  }
  return $this;
}