高级配置

要扩展 Google 跟踪代码管理器的功能,您可以添加函数调用变量和函数调用代码。借助函数调用变量,您可以捕获预注册函数的调用所返回的值。而函数调用代码可让您执行预注册函数,以触发 Google 跟踪代码管理器中的代码模板目前不支持的其他衡量和再营销工具的匹配项。

添加自定义代码和变量

要通过函数调用添加自定义代码或自定义变量,请执行如下步骤:

  1. 要创建自定义代码,请创建实现 TAGCustomFunction 协议的类:
    @implementation MYCustomTag<TAGCustomFunction>
    
    - (NSObject*)executeWithParameters:(NSDictionary*)parameters {
      // Add custom tag implementation here.
    }
    
    @end
    
  2. 要创建自定义变量,请创建实现 TAGCustomFunction 协议的类:
    @implementation MYCustomVariable<TAGCustomFunction>
    
    - (NSObject*)executeWithParameters:(NSDictionary*)parameters {
      // Return the value of the custom variable.
      return @42;
    }
    
    @end
    
  3. 确保链接器在链接时优化过程中不会删除您的类。
  4. 在 Google 跟踪代码管理器的网页界面中,使用类名称设置代码和变量。