OGeek|极客世界-中国程序员成长平台

标题: android - Google Analytics for iOS 仅在 WiFi 可用时发送跟踪,否则缓存 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 03:19
标题: android - Google Analytics for iOS 仅在 WiFi 可用时发送跟踪,否则缓存

我在这里搜索了类似的帖子,但没有找到答案,所以如果我没有找到,请标记这个重复的帖子。 所以我的问题是:我在 Android 和 iOS 上都使用 Google Analytics,两者都面临同样的问题。我希望 GA 仅在 WiFi 可用时发送跟踪,这可以通过检查网络状态轻松完成。但是现在我希望 GA 在没有 WiFi 可用时缓存事件/屏幕,并在 Wifi 可用时发送它。

我在文档中发现缓存只在没有互联网可用的情况下写入,所以我想问的是:有没有办法强制 GA 缓存跟踪,即使 3G 可用? SDK中没有找到这样的方法。

请帮忙。

谢谢。



Best Answer-推荐答案


要在 iOS 应用程序中实现此功能,您可能需要下载 this Apple sample或(我更喜欢)this handy github project

如果你选择第二种方式,你只需要像这样在启动时创建和配置Reachability类实例

// disable automatic sending of statistics 
[GAI sharedInstance].dispatchInterval = 0;

Reachability* reach = [Reachability reachabilityForLocalWiFi];
reach.reachableBlock = ^(Reachability *reach){
    [GAI sharedInstance].dispatchInterval = 20; 

    // you also may send cached statistics right on WiFi appear
    [[GAI sharedInstance] dispatch];
};

reach.unreachableBlock = ^(Reachability *reach) {
    // disable automatic upload, this will force GAI to cache all hits 
    // until you call dispatch or set dispatchInterval
    [GAI sharedInstance].dispatchInterval = 0;
};

关于android - Google Analytics for iOS 仅在 WiFi 可用时发送跟踪,否则缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18131395/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4