Skip to content

Commit cc172c2

Browse files
committed
Explain DI types in README
1 parent 649944d commit cc172c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

ARCHITECTURE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,23 @@ Product clicks are tracked through a specific template called `script-product-cl
8181
</arguments>
8282
</referenceBlock>
8383
```
84+
85+
## Extending or changing data mappers
86+
In various classes in the namespace `Yireo\GoogleTagManager2\DataLayer\Mapper`, like the `Yireo\GoogleTagManager2\DataLayer\Mapper\ProductDataMapper` class, data is being fetched and mapped towards the structure that GTM expects (as we see it). If you want the structure to be different, you can use a DI type to hook into the constructor argument `dataLayerMapping` and add your own class:
87+
88+
```xml
89+
<?xml version="1.0"?>
90+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
91+
<type name="Yireo\GoogleTagManager2\DataLayer\Mapper\ProductDataMapper">
92+
<arguments>
93+
<argument name="dataLayerMapping" xsi:type="array">
94+
<item name="example" xsi:type="object">Yireo\Example\DataLayer\Mapper\AdditionalProductDataMapper</item>
95+
</argument>
96+
</arguments>
97+
</type>
98+
</config>
99+
```
100+
101+
Next, your custom class `Yireo\Example\DataLayer\Mapper\AdditionalProductDataMapper` needs to implement the interface `Yireo\GoogleTagManager2\Api\Data\ProductTagInterface` (specific for this product data mapping) and/or `Yireo\GoogleTagManager2\Api\Data\TagInterface` (for generic data mapping).
102+
103+
The XML property name `example` is the tag property added to GTM. If an existing property name, like `item_id`, is used, it will override the existing tag value.

0 commit comments

Comments
 (0)