@virginie
To combine GTM default macros and jQuery, you can use the following steps:
- In your GTM container, create a custom HTML tag and add your jQuery code to the tag.
- Within the jQuery code, you can access GTM default macros using the built-in dataLayer object. For example, you can use the following code to access the current page URL:
1
|
var currentUrl = dataLayer[0].pageUrl;
|
- You can then use the jQuery code to manipulate the page based on the values of the GTM default macros. For example, you can use the following code to add a class to a specific element based on the value of the page type macro:
1
2
3
|
if (dataLayer[0].pageType == 'homepage') {
$('.element').addClass('homepage');
}
|
- Save and publish your custom HTML tag in GTM to ensure that it runs on your website.
By combining GTM default macros and jQuery, you can create powerful tracking and customization solutions for your website.