PHPackages                             dekar91/yii2-datalayer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dekar91/yii2-datalayer

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

dekar91/yii2-datalayer
======================

DataLayer integration for the Yii framework

v1.0.5(2y ago)21092[4 PRs](https://github.com/dekar91/yii2-datalayer/pulls)MITPHPPHP &gt;=7.4

Since Apr 28Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dekar91/yii2-datalayer)[ Packagist](https://packagist.org/packages/dekar91/yii2-datalayer)[ RSS](/packages/dekar91-yii2-datalayer/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (8)Versions (13)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/a0611f33f945cd5ec8c381d17a277b8bafefbae4fddfb6d2718fbea9e9a37b4e/68747470733a2f2f706f7365722e707567782e6f72672f64656b617239312f796969322d646174616c617965722f762f737461626c65)](https://packagist.org/packages/dekar91/yii2-datalayer)[![License](https://camo.githubusercontent.com/7f2e00a78933eb5b8267d480731436e53d2a188d86e49238476cca473408dee7/68747470733a2f2f706f7365722e707567782e6f72672f64656b617239312f796969322d646174616c617965722f6c6963656e7365)](https://packagist.org/packages/dekar91/yii2-datalayer)[![Total Downloads](https://camo.githubusercontent.com/bcaa95e82b0046bbd69f4679ee0fee9998378129951ed96fdcaf5bf014c14044/68747470733a2f2f706f7365722e707567782e6f72672f64656b617239312f796969322d646174616c617965722f646f776e6c6f616473)](https://packagist.org/packages/dekar91/yii2-datalayer)[![Build Status](https://camo.githubusercontent.com/e7b1aa15aa15daf3c16e22f2f556d5711e386d7227d9adbf9524dd7c09474a53/68747470733a2f2f7472617669732d63692e6f72672f64656b617239312f796969322d646174616c617965722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dekar91/yii2-datalayer)

Yii2 DataLayer helper
=====================

[](#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
------------

[](#installation)

- The minimum required PHP version is PHP 7.1,
- [Yii2](https://www.yiiframework.com/) is required.

### Using composer

[](#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
-------------

[](#configuration)

Plugin involves both PHP and JavaScript functionality. PHP component supports following parameters:

ParameterDefaultDescriptionautoPublishtrueWhether catch EVENT\_END\_PAGE event in order to render DataLayer. If false you should render datalayer by yourself though getJs or render methodobservers\['ec' =&gt; \['class' =&gt; DataLayerEc::class\]\]Array of classes may be used like wrapper on datalayer accessible by key each element must be following format: 'key' =&gt; \['class' =&gt; {name of class to be loaded}, 'options' =&gt; {Additional options}.customEvents\[\]Array of event must be handled by JavaScript.Format: \['jsSelector' =&gt; '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()-&gt; dalaLayer-&gt;ec, click on .btn-checkout will be handled and event information will be pushed in dataLayer.

Usage
-----

[](#usage)

### Basic usage

[](#basic-usage)

You can push in dataLayer before rendering though **Yii::app()-&gt; dalaLayer-&gt;push();**

#### Methods

[](#methods)

MethodDescriptionrender($return = false)Render or return dataLayer Js variablepush(array $data, string $key = null)push data to dataLayer with corresponding key.&amp;getItem($key)return element of dataLayer by link### Enhanced e-commerce

[](#enhanced-e-commerce)

Some basic functions of [Enhanced e-commerce](https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce) 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:

[](#methods-1)

MethodcurrencyCode(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

[](#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()-&gt;dataLayer-&gt;customClass. DataLayer object will be passed as first parameter in constructor.

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~395 days

Recently: every ~494 days

Total

6

Last Release

1008d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v1.0.4PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13837421?v=4)[Denis Karakoliuchka](/maintainers/dekar91)[@dekar91](https://github.com/dekar91)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![dekar91](https://avatars.githubusercontent.com/u/13837421?v=4)](https://github.com/dekar91 "dekar91 (2 commits)")

---

Tags

helperyii2datalayer

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/dekar91-yii2-datalayer/health.svg)

```
[![Health](https://phpackages.com/badges/dekar91-yii2-datalayer/health.svg)](https://phpackages.com/packages/dekar91-yii2-datalayer)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
