【问题标题】:Using Google Tag Manager with Xamarin Google Analytics component results in error将 Google Tag Manager 与 Xamarin Google Analytics 组件一起使用会导致错误
【发布时间】:2015-02-03 14:35:55
【问题描述】:

我正在尝试在使用 Xamarin 构建的 iOS 应用中使用 Google 跟踪代码管理器实现跟踪,但我无法获得容器。我的应用程序日志中出现此错误:“GoogleTagManager 错误:通知程序必须为非零”。

我使用 Google Developers 网站上的 Google Tag Manager Getting Started 指南来制作这段代码。

public class TagManagerService : NSObject, ITAGContainerOpenerNotifier
{
    TAGContainer container;
    readonly TAGDataLayer dataLayer;
    readonly TAGManager tagManager;

    public TagManagerService()
    {
        tagManager = TAGManager.GetInstance;
        dataLayer = tagManager.DataLayer;

        #if DEBUG
        tagManager.Logger.LogLevel = TAGLoggerLogLevelType.Verbose;
        #endif

        TAGContainerOpener.OpenContainer(Constants.TagManagerContainerId, tagManager, TAGOpenType.PreferFresh, 0, this);
    }

    public void ContainerAvailable(TAGContainer container)
    {
        this.container = container;
    }
}

【问题讨论】:

    标签: ios xamarin.ios xamarin google-tag-manager


    【解决方案1】:

    此错误已在最新版本的 Google Analytics 库 3.0.10.3 according to Xamarin Dev team 上得到修复。

    您可以查看library page here 以获取更多说明。

    【讨论】:

      【解决方案2】:

      如果您必须进一步加强电子商务实施,如果您想加强应用转化,您应该这样做,请查看 my blog post 了解如何做到这一点。

      关键在于 gtm 上嵌套值的正确对象结构,如下示例代码

      NSMutableArray products = new NSMutableArray ();
              if (LIST != null && LIST.Count > 0) {
                  foreach (var b in LIST) {
                      NSDictionary p = new NSDictionary ("name", b.name, "id", b.id,
                          "price", b.total, "category", b.category, "quantity", b.quantity);
      
                      products.Add (NSObject.FromObject (p));
                  }
      
                  NSDictionary actionField = new NSDictionary ("id", "value", "revenue", "value", "tax", "value", "shipping", "value", "coupon","value");
                  NSDictionary purchase = new NSDictionary ("purchase", new NSDictionary ("products", NSObject.FromObject(products) , "actionField", NSObject.FromObject(actionField)));
      
                  NSDictionary data = new NSDictionary ("event", "purchase", "ecommerce", NSObject.FromObject(purchase));
      
                  manager.DataLayer.Push (data);
              }
      

      【讨论】:

        猜你喜欢
        • 2021-12-03
        • 2021-01-17
        • 2015-04-30
        • 1970-01-01
        • 1970-01-01
        • 2018-08-31
        • 1970-01-01
        • 1970-01-01
        • 2015-12-26
        相关资源
        最近更新 更多