Search code examples
htmltwiganalyticsshopwaregtag.js

How to take an element with gtag?


I'm setting up an HTML.twig page extension and I want to take a text from page body with gtag

This is for a shopware page

I've already tried this but it does not seem to work:

gtag('config', 'GA_MEASUREMENT_ID', {
    'page_title' : 'homepage',
    'page_path': '/home'
});

but this code is alright: gtag('config', 'Example');

Instead of "Example" I want to take some text from the page body.


Solution

  • {% if page.product.name %}
        gtag('product', '{{ page.product.name }}'); // for example :)
    {% endif %}