简体   繁体   English

Google跟踪代码管理器动态功能

[英]Google Tag Manager Dynamic Function

Is there anyone who knows how to use dynamic function in Gtm. 有谁知道如何在Gtm中使用动态功能。 For ex I create a new variable(custom javascript in GTM) called GetName and which is just take 1 parameter. 例如,我创建了一个名为GetName的新变量(GTM中的自定义javascript),该变量仅带有1个参数。

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

Now, I want to create a new custom javascript. 现在,我想创建一个新的自定义javascript。 And that will call the GetName function. 然后将调用GetName函数。 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. 有谁知道如何在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. 例如,如果要在事件标签中使用它们,则需要提供返回值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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