2017 © Pedro Peláez
 

yii2-extension yii2-datalayer

DataLayer integration for the Yii framework

image

dekar91/yii2-datalayer

DataLayer integration for the Yii framework

  • Thursday, June 14, 2018
  • by dekar91
  • Repository
  • 1 Watchers
  • 0 Stars
  • 43 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 139 % Grown

The README.md

Latest Stable Version License Total Downloads Build Status, (*1)

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., (*2)

Installation

  • The minimum required PHP version is PHP 7.1,
  • Yii2 is required.

Using composer

Add following line in your required section:, (*3)

"dekar91/yii2-datalayer": "@stable"

Then, register the component in your application config:, (*4)

        'dataLayer' => [
            'class' => 'dekar91\datalayer\DataLayer'
        ],

Configuration

Plugin involves both PHP and JavaScript functionality. PHP component supports following parameters:, (*5)

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:, (*6)

        '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., (*7)

Usage

Basic usage

You can push in dataLayer before rendering though Yii::app()-> dalaLayer->push();, (*8)

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., (*9)

Be careful! Do not push data in ajax request, it will not take effect., (*10)

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., (*11)

The Versions

14/06 2018

dev-master

9999999-dev

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

dev-dev

dev-dev

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

dev-releases

dev-releases

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

v1.0.3

1.0.3.0

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

v1.0.2

1.0.2.0

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

v1.0.0

1.0.0.0

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer

28/04 2018

v1.0.1

1.0.1.0

DataLayer integration for the Yii framework

  Sources   Download

MIT

The Requires

 

by Denis Karakoliuchka

yii2 helper datalayer