在iOS上的Google Analytics中使用数字自定义指标

时间:2016-10-14 10:15:11

标签: ios swift google-analytics

我需要使用简单的Google分析事件设置自定义指标。

我使用以下方法:设置事件,然后设置自定义指标,然后全部发送:

GAIDictionaryBuilder.createEvent(withCategory: <#T##String!#>, action: <#T##String!#>, label: <#T##String!#>, value: <#T##NSNumber!#>).set(<#T##value: String!##String!#>, forKey: <#T##String!#>).build()

但我需要在自定义指标的值的参数中传递INT,而不是STRING。我的自定义指标是数值。

我不明白为什么我找不到任何&#34; set&#34;函数的值为INT。

在实践中:

let build = GAIDictionaryBuilder.createEvent(withCategory: "cat", action: "act", label: "lab", value: nil).set("100", forKey: GAIFields.customMetric(for: 1)).build() as [NSObject : AnyObject]
GAI.sharedInstance().defaultTracker.send(build)

结果:

Saved hit: {
    parameters =     {
        "&_crc" = 0;
        "&_s" = 0;
        "&_u" = ".nteoyAL";
        "&_v" = "mi3.1.7";
        "&a" = 114102722;
        "&aid" = "com.dve.apptest";
        "&an" = PrizeeTestGA;
        "&av" = "1.0";
        "&cid" = "28c24faa-f546-43e6-b596-e5a1c4e61373";
        "&cm1" = 100;
        "&dm" = "x86_64";
        "&ds" = app;
        "&ea" = act;
        "&ec" = cat;
        "&el" = lab;
        "&ev" = "<null>";
        "&sr" = 750x1334;
        "&t" = event;
        "&tid" = "UA-108352-26";
        "&ul" = "en-us";
        "&v" = 1;
        "&z" = 17487374570739913012;
        gaiVersion = "3.17";
    };
    timestamp = "2016-10-14 10:02:38 +0000";

}

其中&#34;&amp; cm1&#34; = 100为STRING ......

1 个答案:

答案 0 :(得分:3)

实际上,服务器会转换Int中的String。明显!