记录事件Firebase Analytics for Android

时间:2016-05-25 13:49:59

标签: android firebase firebase-analytics

我正在尝试实施Firebase Analytics for Android,但它无效。

到目前为止,我所做的是https://firebase.google.com/docs/analytics/android/start/

private FirebaseAnalytics mFirebaseAnalytics;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //...
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);

    mFirebaseAnalytics.setUserProperty("dev", "TEST");

    // [START custom_event]
    Bundle params = new Bundle();
    params.putString("dev_name", "dev_name_test");
    params.putString("dev_description", "Testing log events");
    mFirebaseAnalytics.logEvent("dev_test", params);
    // ....

我也禁用了disable Instant Run

  

禁用“即时运行”:打开“设置”或“首选项”对话框。   导航到构建,执行,部署>即时运行。取消选中   启用即时运行

旁边的框

知道为什么不工作?我在firebase仪表板中看不到任何内容。

2 个答案:

答案 0 :(得分:5)

验证记录和上传事件的最快方法是启用调试日志记录:View events in the Android Studio debug log

总之,在连接设备/仿真器的命令行中运行它:

//
//  CustomModeWithTimer.swift
//  BetaVersion0.1
//
//  Created by James Ikeler on 5/26/16.
//  Copyright © 2016 James Ikeler. All rights reserved.
//

import UIKit
import Foundation


var CustomNumber1 = UInt32(CustomInputForGame)
var CustomNumber2 = UInt32(CustomInput2ForGame)
var Random = arc4random_uniform(CustomNumber2) + CustomNumber1
var Random2 = arc4random_uniform(CustomNumber2) + CustomNumber1
var UnConvertInt = 0
var scorecustom = 0
var TimerCustom = NSTimer()
var CountDownCustom = 10
var GameOverCustom = UIAlertView()
var AnswerCustom = Int(CustomNumber1 * CustomNumber2)


class CustomModeWithTimer: UIViewController {

@IBOutlet weak var CustomInputForGame3: UITextField!
@IBOutlet weak var QuestionForCustomGame: UILabel!
@IBOutlet weak var ScoreLabelForCustom: UILabel!
@IBOutlet weak var TimerCustomLabel: UILabel!
@IBOutlet weak var RightOrWrongCustom: UILabel!

@IBOutlet weak var CustomImgForGame: UIImageView!

func IfAnswerWrong() {
    print("TEST\(AnswerCustom)")
    CustomInputForGame3.text = ""
    CustomImgForGame.image = UIImage(named:  "Label")
    CustomImgForGame.hidden = false
    RightOrWrongCustom.hidden = false
    RightOrWrongCustom.text = "Wrong!"
    RightOrWrongCustom.textColor = UIColor(red: 225, green: 0, blue: 0, alpha: 1)

}


func IfAnswerRight() {
        CountDownCustom = 10
        scorecustom += 1
        ScoreLabelForCustom.text = "Score: \(scorecustom)"
        Random = arc4random_uniform(CustomNumber2) + CustomNumber1
        Random2 = arc4random_uniform(CustomNumber2) + CustomNumber1

        QuestionForCustomGame.text = "\(Random) x \(Random2)"
        AnswerCustom = Int(Random * Random2)
        CustomImgForGame.image = UIImage(named: "Label")
        RightOrWrongCustom.hidden = false
        CustomImgForGame.hidden = false
        RightOrWrongCustom.text = "Right!"
        RightOrWrongCustom.textColor = UIColor(red: 0, green: 225, blue: 0, alpha: 1)
        CustomInputForGame3.text = ""


}

@IBAction func ConfirmAnswerCustom(sender: AnyObject) {
    TimerCustom.invalidate()
    TimerCustom = NSTimer.scheduledTimerWithTimeInterval(0.8, target: self,selector: Selector("UpdateClockCustom"), userInfo:  nil, repeats: true)
    let InputAnswerCustom = Int(CustomInputForGame3.text!)
    if InputAnswerCustom == AnswerCustom {
        IfAnswerRight();
    } else {
        IfAnswerWrong();

    }
}

func UpdateClockCustom() {
    TimerCustomLabel.text = ("Time: \(CountDownCustom--)")
    if CountDownCustom == -2 {
        TimerCustom.invalidate()
        GameOverCustom.title = "Game Over!"
        GameOverCustom.message = "Nice job you got a score of \(scorecustom).The answer to the question you missed was \(AnswerCustom)!"
        GameOverCustom.addButtonWithTitle("Play Again!")
        GameOverCustom.show()
    }
}
override func viewDidLoad() {
    super.viewDidLoad()


   // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

您应该在记录事件或设置属性以及上载数据时看到消息。

答案 1 :(得分:1)

我的体验大约需要2-4个小时才能在控制台中显示任何事件。另请注意,控制台中的默认视图是过去30天,您可能希望将其切换为 Today 。还需要考虑的是,在自定义事件的控制台中,您只能查看事件dev_test,而不能查看已添加为自定义参数的字符串。您必须将事件导出到BigQuery才能查看已添加的自定义参数dev_name abd dev_descriptionSee my similar question here which may also help.