如何使用Google Tag Manager V5快速编写代码,尤其是针对增强型电子商务部分?

时间:2019-04-25 09:21:57

标签: swift firebase google-analytics google-tag-manager

我正在尝试将gtm v5用于Swift,但是我发现它无法正常工作。

它不会向Google Analytics(分析)发送任何数据,但同时不会给我错误。我已经仔细检查了GTM,所有内容与Google跟踪代码管理器文档中的内容相同。

   override func viewDidLoad() 
   {
    super.viewDidLoad()

    let  product1 : [String : Any] = [
        AnalyticsParameterItemID : "sku1234", // ITEM_ID or ITEM_NAME is required.
        AnalyticsParameterItemName : "Android Jogger Sweatpants",
        AnalyticsParameterItemCategory : "Apparel/Men/Pants",
        AnalyticsParameterItemVariant : "Blue",
        AnalyticsParameterItemBrand : "Google",
        AnalyticsParameterPrice : 39.99,
        AnalyticsParameterCurrency : "USD",  // Item-level currency unused today.
        AnalyticsParameterQuantity : 1
    ]

    let items : Array = [product1]

    let ecommerce : [String : Any] = [
        "items" : items,
        "screenName" : "Thank you page",
        AnalyticsParameterItemList : "Search Results", // List name.
        AnalyticsParameterTransactionID : "T12345",
        AnalyticsParameterAffiliation : "Google Store - Online",
        AnalyticsParameterValue : 75.98, // Revenue.
        AnalyticsParameterTax : 3.80,
        AnalyticsParameterShipping : 5.34,
        AnalyticsParameterCurrency : "USD",
        AnalyticsParameterCoupon : "SUMMER2017"
    ]

    Analytics.logEvent(AnalyticsEventEcommercePurchase, parameters: ecommerce)

    print("Success!")
}

1 个答案:

答案 0 :(得分:0)

请确保已根据documentation配置了标签,增强型电子商务功能应设置为 true

Tag Type: Universal Analytics 
Track Type: Screen View
Enhanced Ecommerce Features: True
Read data from: Firebase
Event Trigger, e.g.: (Custom > Some Events) Event Name equals ecommerce_purchase