Skip to content

Commit

Permalink
Merge pull request #185 from samicoman/master
Browse files Browse the repository at this point in the history
sign_up event
  • Loading branch information
jissereitsma authored Sep 6, 2023
2 parents 60f4b6b + 1c47954 commit 1697f1c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions DataLayer/Event/SignUp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Yireo\GoogleTagManager2\DataLayer\Event;

use Yireo\GoogleTagManager2\Api\Data\EventInterface;

class SignUp implements EventInterface
{
public function get(): array
{
return [
'event' => 'sign_up',
'method' => 'Standard' // @TODO: implement mapping based on the route used?
];
}
}
28 changes: 28 additions & 0 deletions Observer/TriggerSignUpDataLayerEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace Yireo\GoogleTagManager2\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Yireo\GoogleTagManager2\Api\CustomerSessionDataProviderInterface;
use Yireo\GoogleTagManager2\DataLayer\Event\SignUp as SignUpEvent;

class TriggerSignUpDataLayerEvent implements ObserverInterface
{
private CustomerSessionDataProviderInterface $customerSessionDataProvider;
private SignUpEvent $signUpEvent;

public function __construct(
CustomerSessionDataProviderInterface $customerSessionDataProvider,
SignUpEvent $signUpEvent
) {
$this->customerSessionDataProvider = $customerSessionDataProvider;
$this->signUpEvent = $signUpEvent;
}

public function execute(Observer $observer)
{
$eventData = $this->signUpEvent->get();
$this->customerSessionDataProvider->add('sign_up_event', $eventData);
}
}
4 changes: 4 additions & 0 deletions etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<observer name="Yireo_GoogleTagManager2::triggerLogoutDataLayerEvent" instance="Yireo\GoogleTagManager2\Observer\TriggerLogoutDataLayerEvent" />
</event>

<event name="customer_register_success">
<observer name="Yireo_GoogleTagManager2::triggerSignUpDataLayerEvent" instance="Yireo\GoogleTagManager2\Observer\TriggerSignUpDataLayerEvent" />
</event>

<event name="wishlist_add_product">
<observer name="Yireo_GoogleTagManager2::triggerAddToWishlistDataLayerEvent" instance="Yireo\GoogleTagManager2\Observer\TriggerAddToWishlistDataLayerEvent" />
</event>
Expand Down

0 comments on commit 1697f1c

Please sign in to comment.