lexik / lexikdatalayerbundle Goto Github PK
View Code? Open in Web Editor NEWManipulate the Google Tag Manager Data Layer from your Symfony application
Manipulate the Google Tag Manager Data Layer from your Symfony application
A tree builder without a root node is deprecated since Symfony 4.2 and will not be supported anymore in 5.0.
The "Symfony\Component\Config\Definition\Builder\TreeBuilder::root()" method called for the "lexik_data_layer" configuration is deprecated since Symfony 4.3, pass the root name to the constructor instead.
See https://github.com/lexik/LexikDataLayerBundle/blob/master/DependencyInjection/Configuration.php
Fix would be:
<?php
namespace Lexik\Bundle\DataLayerBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* Configuration
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('lexik_data_layer');
// BC layer for symfony/config < 4.2
$rootNode = method_exists($treeBuilder, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('apy_breadcrumb_trail');
return $treeBuilder;
}
}
I found a probable issue with the autowiring DataLayerManager
to the Controller. When I add DataLayerManager
as a constructor parameter to the Controller, there is an exception:
Cannot autowire service "My\App\HomepageController": argument "$dataLayerManager" of method "__construct()" references class "Lexik\Bundle\DataLayerBundle\Manager\DataLayerManager" but no such service exists. It cannot be auto-registered because it is from a different root namespace.
It works fine when I try to inject \Doctrine\ORM\EntityManagerInterface
(so autowiring a class from a different namespace works in general).
I found this workaround - just add this to services.yaml
:
services:
Lexik\Bundle\DataLayerBundle\Manager\DataLayerManager: '@lexik_data_layer.manager.data_layer_manager'
Lexik\Bundle\DataLayerBundle\Collector\CollectorChain: '@lexik_data_layer.collector.collector_chain'
Even this works:
services:
Lexik\Bundle\DataLayerBundle\Manager\DataLayerManager:
Lexik\Bundle\DataLayerBundle\Collector\CollectorChain:
Thanks for the Bundle ๐ I really like the idea of mimicking the flash messages behaviour as it works great for tracking conversions after submitting the form + redirect.
I dont know I am getting thhis error in production:
stderr: PHP Fatal error: Call to a member function getUser() on a non-object in /var/www/vhosts/arvalcarenet.com/releases/20170411094121/vendor/lexik/data-layer-bundle/Lexik/Bundle/DataLayerBundle/Collector/UserIdCollector.php on line 33
class UserIdCollector implements CollectorInterface
{
/**
* @var TokenStorageInterface
*/
protected $tokenStorage;
/**
* @param TokenStorageInterface $tokenStorage
*/
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
/**
* {@inheritdoc}
*/
public function handle(&$data)
{
$token = $this->tokenStorage->getToken();
unset($data[0]);
if($token != null){
if ($token->getUser() && $token->getUser() instanceof User) {
$data[0] = array_merge($data,['userId' => $token->getUser()->getUid()]);
}
}
}
}
But I am calling my own service.
From the documentation, what do you mean by:
Don't forget to use it BEFORE you insert the Tag Manager tag.
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.