Google Tag Manager integration for Spryker
composer require fond-of-spryker/google-tagmanager
// ---------- Google Tag Manager
$config[GoogleTagManagerConstants::CONTAINER_ID] = 'GTM-XXXX';
// ---------- Google Tag Manager
$config[GoogleTagManagerConstants::ENABLED] = true;
$config[KernelConstants::CORE_NAMESPACES] = [
[...]
'FondOfSpryker'
];
$this->application->register(new GoogleTagManagerTwigServiceProvider());
Application/layout/layout.twig
between <head></head> tags
{% block googletagmanager_data_layer %} {{ dataLayer('other', {}) }}{% endblock %}
{{ googleTagManager('@GoogleTagManager/partials/tag.twig') }}
after <body> tag
{{ googleTagManager('@GoogleTagManager/partials/tag-noscript.twig') }}
Catalog/catalog/index.twig
{% block googletagmanager_data_layer %}
{% set params = { 'category' : category, 'products' : products} %}
{{ dataLayer('category', params) }}
{% endblock %}
Product/product/detail.twig
{% block googletagmanager_data_layer %}
{% set params = { 'product' : product} %}
{{ dataLayer('product', params) }}
{% endblock %}
Cart/cart/index.twig
{% block googletagmanager_data_layer %}
{{ dataLayer('cart', {}) }}
{% endblock %}
Checkout/checkout/partial/success.twig
{% block googletagmanager_data_layer %}
{% set params = { 'order' : orderTransfer} %}
{{ dataLayer('order', params) }}
{% endblock %}