PHP code example of spatie / laravel4-googletagmanager
1. Go to this page and download the library: Download spatie/laravel4-googletagmanager 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/ */
spatie / laravel4-googletagmanager example snippets
// HomeController.php
public function index()
{
GoogleTagManager::set('pageType', 'productDetail');
return view('home');
}
// Retrieve your Google Tag Manager id
$id = GoogleTagManager::id(); // GTM-XXXXXX
// Check whether script rendering is enabled
$enabled = GoogleTagManager::isEnabled(); // true|false
// Enable and disable script rendering
GoogleTagManager::enable();
GoogleTagManager::disable();
// Add data to the data layer (automatically renders right before the tag manager script). Setting new values merges them with the previous ones. Set als supports dot notation.
GoogleTagManager::set(['foo' => 'bar']);
GoogleTagManager::set('baz', ['ho' => 'dor']);
GoogleTagManager::set('baz.ho', 'doorrrrr');
// [
// 'foo' => 'bar',
// 'baz' => ['ho' => 'doorrrrr']
// ]
$dataLayer = new Spatie\GoogleTagManager\DataLayer();
$dataLayer->set('ecommerce.click.products', $products->toJson());
echo $dataLayer->toJson(); // {"ecommerce":{"click":{"products":"..."}}}