首页 > 解决方案 > 通过 NativeScript 在 GAITracker 上调用方法时出错

问题描述

我正在尝试使用以下代码在 iOS 中调用本机 GoogleAnalytics 跟踪器:

(googleAnalytics.getTracker() as any).setValueForKey(value, (global as any).GAIFields.customDimensionForIndex(key));

value这里是字符串,输出GAIFields.customDimensionForIndex(key)也是字符串)

但我收到了这个错误:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<GAITrackerImpl 0x2811e94a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key &cd1.'

我在这里做错了什么?

标签: nativescript

解决方案


根据官方文档,似乎只setValue支持方法。

尝试,

(googleAnalytics.getTracker() as any).setValue((global as any).GAIFields.customDimensionForIndex(key), value);

推荐阅读