dekar91 / yii2-datalayer
DataLayer integration for the Yii framework
Installs: 102
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 4
Type:yii2-extension
Requires
- php: >=7.4
- bower-asset/inputmask: ~3.3.5
- ezyang/htmlpurifier: *
- yiisoft/yii2: >=2.0
Requires (Dev)
- codeception/codeception: 4.2.x-dev
- codeception/specify: ~2.0.0
- codeception/verify: ~3.0.0
- yiisoft/yii2-debug: ~2.1.19
- yiisoft/yii2-faker: ~2.0.5
This package is auto-updated.
Last update: 2024-09-25 08:31:47 UTC
README
Yii2 DataLayer helper
This extension is managed to help you fulfill dataLayer variable with initial data on fly. Some Google enhanced e-commerce features are also available.
Installation
- The minimum required PHP version is PHP 7.1,
- Yii2 is required.
Using composer
Add following line in your required section:
"dekar91/yii2-datalayer": "@stable"
Then, register the component in your application config:
'dataLayer' => [
'class' => 'dekar91\datalayer\DataLayer'
],
Configuration
Plugin involves both PHP and JavaScript functionality. PHP component supports following parameters:
Configuration example:
'dataLayer' => [
'class' => 'dekar91\datalayer\DataLayer',
'options' => [
'autoPublish' => true,
'observers' => ['ec' => ['class' => DataLayerEc::class]],
'customEvents' => [
['.btn-checkout', 'click' , ['event' => 'checkoutEvent']],
]
]
],
with this configuration you DataLayer will be published, DataLayerEc can be used by Yii::app()-> dalaLayer->ec, click on .btn-checkout will be handled and event information will be pushed in dataLayer.
Usage
Basic usage
You can push in dataLayer before rendering though Yii::app()-> dalaLayer->push();
Methods
Enhanced e-commerce
Some basic functions of Enhanced e-commerce are supported by default class DataLayerEc. Please look though google documentation for further details.
Be careful! Do not push data in ajax request, it will not take effect.
Methods:
User-defined observers
It's possible to extend dataLayer functionality by custom classes. While class is registered though observers property it can be used by Yii::app()->dataLayer->customClass. DataLayer object will be passed as first parameter in constructor.