PHP code example of ezoterik / yii2-google-tag-manager

1. Go to this page and download the library: Download ezoterik/yii2-google-tag-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ezoterik / yii2-google-tag-manager example snippets


 'bootstrap' => ['googleTagManager'],
 'components' => [
     'googleTagManager' => [
         'class' => 'ezoterik\googleTagManager\GoogleTagManager',
         'tagManagerId' => 'GOOGLE_TAG_MANAGER_ID', //Your Google Tag Manager ID without "GTM-" prefix
     ],
 ],
 

 Yii::$app->googleTagManager->dataLayerPushItemDelay('event', 'example_event');
 

Yii::$app->googleTagManager->dataLayerPushItem(null, (object)[
    'event' => 'view_item',
    'ecommerce' => (object)[
        'currency' => 'UAH',
        'value' => '500',
        'items' => [
            (object)[
                'item_name' => 'Product name',
                'item_id' => '12345',
                'price' => '500',
                'item_brand' => 'Analytics',
                'item_category' => 'Very Good Category',
                'item_category2' => 'Very Good Category 2',
                'item_category3' => 'Very Good Category 3',
                'item_category4' => 'Very Good Category 4',
                'item_variant' => 'full',
                'item_list_name' => 'sales',
                'item_list_id' => 'sales2022',
            ],
        ],
    ],
]);

php composer.phar