ios - 将谷歌分析集成到 iOS 应用程序中

标签 ios swift google-analytics

我按照此处的说明将谷歌分析集成到我的应用程序中:https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift#get-config

我现在需要为我的应用程序初始化分析。我已将此代码添加到我的 AppDelegate.swift 文件中:

import UIKit
import <Google/Analytics.h>

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool {
        **// Configure tracker from GoogleService-Info.plist.
        NSError *configureError;
        [[GGLContext sharedInstance] configureWithError:&configureError];
        NSAssert(!configureError, @"Error configuring Google services: %@", configureError);

        // Optional: configure GAI options.
        GAI *gai = [GAI sharedInstance];
        gai.trackUncaughtExceptions = YES;  // report uncaught exceptions
        gai.logger.logLevel = kGAILogLevelVerbose;  // remove before app release**

    }

我收到以下错误消息。

  1. 给我的import <Google/Analytics.h>行时,我收到此消息:“一行中的连续语句必须用 ';' 分隔。

  2. 对于代码的其余部分,尽管我只是将教程中的代码复制到我的文件中,但我遇到了几个错误。请参阅我的屏幕截图。

enter image description here

最佳答案

由于您处于 Swift 项目中,因此您会遇到此问题。您需要创建一个 Objective-C 桥接 header ,并在其中添加导入语句。之后,一切都应该正常工作。查看此答案以了解更多详细信息:

https://stackoverflow.com/a/24005242/1784384

关于ios - 将谷歌分析集成到 iOS 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36270707/

相关文章:

ios - 如何在 PDFView 中选择连续文本以便添加注释?

javascript - 如何在 Rails Controller 中使用 Google Analytics 自定义事件?

angular - 如何在 Angular 10 应用程序仪表板中包含 firebase 分析?

google-analytics - 维度关系不正确的 Google Analytics 跟踪事件

ios - 使用 NMAMapViewDelegate 识别标记选择?

iOS 8.1 模拟器本地化损坏 (NSLocalizedString)

ios - 自定义动态 TableViewCell 文本定位

ios - NSPredicate 多个 ANY 查询与 CoreData

ios - 搜索栏文本字段颜色不会改变

swift - UITableViewCell 按钮和分段控件