简体   繁体   中英

Google Tag Manager Dynamic Function

Is there anyone who knows how to use dynamic function in Gtm. For ex I create a new variable(custom javascript in GTM) called GetName and which is just take 1 parameter.

function(name)
 {
   console.log(name);
   return;
 }

Now, I want to create a new custom javascript. And that will call the GetName function. But I could not call it. I think I am using wrong syntax.

  function()
  {
   {{GetName("test")}} => That not worked
   {{GetName "test"}}  => That not worked

   return;
  }

Is there anyone who knows how to call that function in GTM. Thanks

You could try this:

Your first function to return the name:

function(){
    return function(name){
        console.log(name);
        return;
    }
}

And then to call this:

function(){
    var getName = {{GetName}};
    getName("test");
    return;
}

Whatever is in the double curly braces is the name of the macro itself, and then anything outside of that can be called like any regular function. If you want to use them in an an event tag for example, then you would need to supply the return value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM