Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
Developer Guide
This document is intended for website and mobile developers who want to extend Anowave Magento 2 Google Tag Manager Enhanced Ecommerce module
for Magento 2.x. It describes a few events dispatched by our module. You can hook to these events from your own module and extend the functionality
without modifying the module thus keeping it updatable.
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
MAGENTO 2 CUSTOM EVENTS
ec_get_visitor_data Allows 3rd party modules to modify visitor array []
params: array transport[visitor]
ec_get_update_quantity_attributes Allows 3rd party modules to modify quantity update attributes
params: array transport[response]
ec_get_checkout_products Allows 3rd party modules to modify products array generated at checkout push
params: array transport[products]
ec_get_purchase_push_after Allows 3rd party modules to modify purchase payload
params: transport[response]
ec_get_detail_data_after Allows 3rd party modules to product detail parameters
params: transport[response], transport[product]
ec_order_products_get_after Allows 3rd party modules to modify products array generated at purchase push []
params: transport[products]
ec_get_purchase_attributes Allows 3rd party modules to modify purchase attributes
params: transport[attributes]
ec_get_widget_click_attributes Allows 3rd party modules to modify widget click attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_widget_add_list_attributes Allows 3rd party modules to modify widget add to cart attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_click_attributes Allows 3rd party modules to modify product click attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_add_list_attributes Allows 3rd party modules to modify add to cart from categories attributes e.g. data-attributes="{[]}"
params: transport[attributes]
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
ec_get_click_list_attributes Allows 3rd party modules to modify category click attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_remove_attributes Allows 3rd party modules to modify remove click attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_add_attributes Allows 3rd party modules to modify add to cart attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_search_click_attributes Allows 3rd party modules to modify search list attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_checkout_attributes Allows 3rd party modules to modify checkout step attributes e.g. data-attributes="{[]}"
params: transport[attributes]
ec_get_impression_item_attributes Allows 3rd party modules to modify single item from impressions
params: transport[attributes], transport[entity], transport[product]
ec_get_impression_data_after Allows 3rd party modules to modify impressions array []
params: transport[response]
ec_get_detail_attributes Allows 3rd party modules to modify detail attributes array []
params: transport[attributes], transport[product]
ec_get_impression_related_attributes Allows 3rd party modules to modify related attributes
params: transport[attributes], transport[product]
ec_get_impression_upsell_attributes Allows 3rd party modules to modify upsell attributes
params: transport[attributes], transport[product]
ec_get_detail_data_after Allows 3rd party modules to modify detail array []
params: transport[response], transport[product]
ec_order_products_product_get_after Allows 3rd party modules to modify single transaction product []
params: transport[quote_item], transport[product]
ec_order_products_get_after Allows 3rd party modules to modify transaction products array
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
params: transport[products]
ec_get_search_attributes Allows 3rd party modules to modify search array attributes
params: transport[attributes]
ec_api_measurement_protocol_purchase Allows 3rd party modules to modify payload for measurement protocol
params: [order_id]
ec_get_purchase_push_after Allows 3rd party modules to modify the purchase push
params: transport[response]
EXAMPLE
In the following few lines, you can find an example how to use these events
1. Define your own module in the app namespace
2. Create \etc\frontend\events.xml and hook to any of the events shown above using the following XML instruction
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="ec_get_detail_data_after">
<observer name="extend" instance="<your module>\Observer\Detail" />
</event>
</config>
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
3. Define an observer (Detail.php) in app/code/<your module>/Observer folder and access attributes and data as shown below
<?php
namespace Anowave\Extend\Observer;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
class Detail implements ObserverInterface
{
/**
* Execute (non-PHPdoc)
*
* @see \Magento\Framework\Event\ObserverInterface::execute()
*/
public function execute(EventObserver $observer)
{
$response = $observer->getTransport()->getReponse();
/**
* Modify response (dataLayer[] payload)
*/
$response['custom_attribute'] = __('Custom attribute value');
$observer->getTransport()->setResponse($response);
}
}
4. That’s all.
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
AEC.EventDispatcher()
As of version 100.5.5, we have included a simple event dispatcher to allow third party scripts to modify dataLayer[] payload push via Javascript. It’s a simple
interface that dispatches an event and passes the push payload as event parameter. You can hook your own listeners to those events and add more
parameters to the data being pushed in dataLayer object or modify it as per your requirements.
AEC.EventDispatcher.on('ec.cookie.impression.data', (data) =>
{
data['customData'] = 'sample data';
});
AEC.EventDispatcher() EVENT LIST
ec.add.data
ec.add.swatch.data
ec.add.list.data
ec.remove.data
ec.remove.item.data
ec.update.item.data
ec.click.data
ec.checkout.step.data
ec.checkout.step.option.data
ec.cookie.click.data
ec.cookie.add.data
ec.cookie.remove.data
ec.cookie.visitor.data
ec.cookie.purchase.data
ec.cookie.impression.data
ec.cookie.checkout.step.data
ec.cookie.checkout.step.option.data
Copyright (c) 2023 Anowave Enterprise
All Right Reserved.
ec.cookie.promotion.data
ec.cookie.remarketing.data