Created
February 1, 2019 14:49
-
-
Save wanze/dbdb9976dde4c0738e75e8ba4e17bb72 to your computer and use it in GitHub Desktop.
commerce_google_tag_manager: Example of a CheckoutOption event subscriber
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Drupal\commerce_google_tag_manager\Event\TrackCheckoutStepEvent; | |
<?php | |
class CheckoutOptionSubscriber implements EventSubscriberInterface { | |
public static function getSubscribedEvents() { | |
return [ | |
'commerce_google_tag_manager.track_checkout_step' => 'trackUser' | |
]; | |
} | |
public function trackUser(TrackCheckoutStepEvent $event) { | |
// Only track this option for the first checkout step | |
if ($event->getStepIndex() === 0) { | |
$event_tracker = Drupal::service('commerce_google_tag_manager.event_tracker'); | |
$current_user = Drupal::service('current_user'); | |
$option = $current_user->isAnonymous() ? 'anonymous' : 'authenticated'; | |
$event_tracker->checkoutOption(0, $option); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment