dekar91/yii2-datalayer
Composer 安装命令:
composer require dekar91/yii2-datalayer
包简介
DataLayer integration for the Yii framework
关键字:
README 文档
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:
| Parameter | Default | Description |
|---|---|---|
| autoPublish | true | Whether catch EVENT_END_PAGE event in order to render DataLayer. If false you should render datalayer by yourself though getJs or render method |
| observers | ['ec' => ['class' => DataLayerEc::class]] | Array of classes may be used like wrapper on datalayer accessible by key each element must be following format: 'key' => ['class' => {name of class to be loaded}, 'options' => {Additional options}. |
| customEvents | [] | Array of event must be handled by JavaScript.Format: ['jsSelector' => 'nameOfEvent', 'customEventData'] |
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
| Method | Description |
|---|---|
| render($return = false) | Render or return dataLayer Js variable |
| push(array $data, string $key = null) | push data to dataLayer with corresponding key. |
| &getItem($key) | return element of dataLayer by link |
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:
| Method |
|---|
| currencyCode(string $currencyCode) |
| addProductImpression(array $product) |
| addPromoClick(array $product, array $action = []) |
| addPromoImpression(array $product) |
| addProductClick(array $product, array $action = []) |
| addProductDetails(array $product, array $action = []) |
| addToCart(array $product) |
| removeFromCart(array $product) |
| checkout(array $product, array $action = []) |
| checkoutOption($step, $checkoutOption) |
| purchase(array $purchase, array $products) |
| refund(array $transactionId, array $products = []) |
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.
dekar91/yii2-datalayer 适用场景与选型建议
dekar91/yii2-datalayer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 109 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 04 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「helper」 「yii2」 「datalayer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dekar91/yii2-datalayer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dekar91/yii2-datalayer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dekar91/yii2-datalayer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
GTM integration and dataLayer configuration for Shopware
Datetime helpers for timezone handling
Class helping to generate datalayer
Library with classes to help you do batch.
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
统计信息
- 总下载量: 109
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-04-26