gtm-module icon indicating copy to clipboard operation
gtm-module copied to clipboard

Question: How to use dynamic id's?

Open losbeekos opened this issue 5 years ago • 5 comments

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 avatar Sep 11 '20 08:09 losbeekos

@losbeekos : What are you trying to differentiate with the different IDs? (i.e. logically/functionally)

matt-jay avatar Nov 01 '20 12:11 matt-jay

@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.

losbeekos avatar Nov 02 '20 07:11 losbeekos

If some one has any solution for this Question, would be helpfull to me too :)

isuke01 avatar Jan 14 '21 12:01 isuke01

Hi, Any update for this issue ?

owalid avatar Mar 24 '21 18:03 owalid

Still waiting :)

isuke01 avatar Mar 25 '21 08:03 isuke01