PHP code example of label84 / laravel-tagmanager

1. Go to this page and download the library: Download label84/laravel-tagmanager 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/ */

    

label84 / laravel-tagmanager example snippets


// app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        ...
        \Illuminate\Session\Middleware\StartSession::class,
        \Label84\TagManager\Http\Middleware\TagManagerMiddleware::class,
        ...

use Label84\TagManager\Facades\TagManager;

TagManager::push(['foo' => 'bar']);

use Label84\TagManager\Facades\TagManager;

TagManager::event('kissed', ['status' => 'failed', 'count' => 0]);
TagManager::login(['foo' => 'bar']);
TagManager::register(['foo' => 'bar']);

// app/Http/Kernel.php

protected $middlewareGroups = [
    'web' => [
        ...
        \Label84\TagManager\Http\Middleware\TagManagerMiddleware::class,
        \Label84\TagManager\Http\Middleware\TagManagerUserIdMiddleware::class,
        ...

use Label84\TagManager\TagManagerItem;

new TagManagerItem(string $id, string $name, float $price, float $quantity);

use Label84\TagManager\TagManagerItem;

$item1 = new TagManagerItem('12345', 'Triblend Android T-Shirt', 15.25, 1);
$item1->itemBrand('Google')       // will add the item parameter { item_brand: 'Google' }
      ->itemCategory('Apparel')   // will add the item parameter { item_category: 'Apparel' }
      ->itemVariant('Gray');      // will add the item parameter { item_variant: 'Gray' }

use Label84\TagManager\Facades\TagManager;

// Product views and interactions
TagManager::viewItemList($items);
TagManager::viewItem($items);
TagManager::selectItem($items);

// Promotion views and interactions
TagManager::viewPromotion($items);
TagManager::selectPromotion($items);

// Pre-purchase interactions
TagManager::addToWishList(string $currency, float $value, $items);
TagManager::addToCart($items);
TagManager::removeFromCart($items);
TagManager::viewCart(string $currency, float $value, $items);

// Purchases, checkouts, and refunds
TagManager::beginCheckout($items);
TagManager::addPaymentInfo(string $currency, float $value, string $paymentType, $items, string $coupon = '');
TagManager::addShippingInfo(string $currency, float $value, string $shippingTier, $items, string $coupon = '');
TagManager::purchase(string $transactionId, string $affiliation, string $currency, float $value, float $tax, float $shipping, $items, string $coupon = '');
TagManager::refund(string $transactionId, string $affiliation, string $currency, float $value, float $tax, float $shipping, $items, string $coupon = '');

use Label84\TagManager\Facades\TagManager;

TagManager::purchase('00001', 'Google', 'EUR', 12.10, 2.10, 0, [
    new TagManagerItem('12345', 'Triblend Android T-Shirt', 10.00, 1),
]);

use Label84\TagManager\Facades\MeasurementProtocol;

MeasurementProtocol::event('some_event', ['foo' => 'bar']);

// Set a specific User-ID for this event (you can customize the key in the config file)
MeasurementProtocol::user($someUser)->event('some_event', ['foo' => 'bar']);

use Label84\TagManager\Facades\MeasurementProtocol;

dd(
    MeasurementProtocol::debug()->event('some_event', ['foo' => 'bar'])
);
sh
php artisan vendor:publish --provider="Label84\TagManager\TagManagerServiceProvider" --tag="config"