gtm-module
gtm-module copied to clipboard
Question: How to use dynamic id's?
So I have a gtm middleware to be able to set dynamic GTM id's on its route, but I can't get it to work as I don't know the proper way to set the dynamic id's. As you can see in the example below I use the init function at the moment but this will result in multiple container script tags to be rendered.
export default function ({ $gtm, route, env }) {
if (env.ENVIRONMENT === 'development') return;
if (route.fullPath.includes('/locations/location-1')) $gtm.init('GTM-location-1');
if (route.fullPath.includes('/locations/location-2')) $gtm.init('GTM-location-2');
}
Can someone please send me in the right direction here?
@losbeekos : What are you trying to differentiate with the different IDs? (i.e. logically/functionally)
@matt-jay I know it's a bit odd but here goes. This client has multiple locations on their website, these locations are kind of like sub sites in the main site. Each location has it's own marketing company that handles its Google Tag Manager and all things related to that. So what I want to do is register those specific GTM ID's on each location route and de-register when you leave that location ofcourse.
If some one has any solution for this Question, would be helpfull to me too :)
Hi, Any update for this issue ?
Still waiting :)