简体   繁体   中英

Google Analytics not Posting Events for my iOS application

I've written an iOS application in Swift, which uses Firebase for it's Database and Authorization. This is just a small portion of my code. I am using a Timer class in a separate file that tracks how much time has been taken. From looking at the logs, the timer class works accurately, and the code inside of the if let interval = MyTimer.shared.measure(key: "login") does work, because time is logged to the console.

I am also using Google Analytics to track screens, as well as actions (pressing log-in button, activating after notifications, etc.).

The problem is that I'm just not seeing events in Google Analytic's dashboard. I've waited 2-3 days already, and nothing. I've also been looking at the realtime dashboard. I am seeing that screen tracking is definitely working in real time, it's just events that are not showing up (I am monitoring real time events and events, in general).

I'm not sure what I'm doing wrong. If someone sees a problem, I definitely appreciate the help.

import UIKit
import FirebaseAuth
import FirebaseAnalytics

class SignInVC: UIViewController {

    @IBOutlet weak var EmailTextField: UITextField!
    @IBOutlet weak var PasswordTextField: UITextField!

    public let MAIN_SEGUE = "MainVC"

    override func viewDidLoad() {
        super.viewDidLoad()

        MyTimer.shared.start(withKey: "login")

    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        guard let tracker = GAI.sharedInstance().defaultTracker else { return }
        tracker.set(kGAIScreenName, value: "LogIn Screen")

        guard let builder = GAIDictionaryBuilder.createScreenView() else { return }
        tracker.send(builder.build() as [NSObject : AnyObject])
    }

    @IBAction func LogIn(_ sender: Any) {

        if (EmailTextField.text != "" && PasswordTextField.text != "") {

        AuthProvider.Instance.login(withEmail: EmailTextField.text!, password: PasswordTextField.text!, loginHandler: { (message) in

            if (message != nil) {
                self.alertUser(title: "Problem with Authentication", message: message!);
            }
            else{

                /// Tracking - Login

                guard let tracker = GAI.sharedInstance().defaultTracker else { return }


                if let interval = MyTimer.shared.measure(key: "login") {

                    print("Logging time to login: \(interval)")

                    guard let builder_event = GAIDictionaryBuilder.createEvent(withCategory: "Buttons_Events", action: "LogIn", label: "LogIn button pressed", value: interval as NSNumber) else { return}

                    tracker.send(builder_event.build() as [NSObject : AnyObject])

                }

                ///

                self.performSegue(withIdentifier: self.MAIN_SEGUE, sender: nil)
                }
            });
        }
        else{
            alertUser(title: "Email and Password Required", message: "Please enter a valid email and password");
        }

    }

EDIT:

Here is the log for the login. I tried to 'x' out any information that could possibly be personal.

Logging time to login: 38.25076597929 2017-06-27 17:40:05.256 Example
App [xxxxxxxxxxxx] VERBOSE: GoogleAnalytics 3.17
-[GAIBatchingDispatcher persist:] (GAIBatchingDispatcher.m:518): Saved hit: {
parameters = {
"&_crc" = 0;
"&_s" = 60;
"&_u" = ".oyL";
"&_v" = "mi3.1.7";
"&a" = xxxxxxxxx;
"&aid" = "xxxxxxxxxxxxx";
"&an" = "xxxxxxxxxxxx";
"&av" = "1.0";
"&cd" = "LogIn Screen";
"&cid" = "xxxxxxxxxxxxxxxxx";
"&dm" = "x86_64";
"&ds" = app;
"&ea" = LogIn;
"&ec" = "Buttons_Events";
"&el" = "LogIn button pressed";
"&ev" = "38.25076597929001";
"&sr" = 750x1334;
"&t" = event;
"&tid" = "xxxxxxxxxxx";
"&ul" = en;
"&v" = 1;
"&z" = xxxxxxxxxxxxxxx;
gaiVersion = "3.17";
};
timestamp = "2017-06-28 00:40:05 +0000"; }

尝试在tracker.send(builder_event.build() as [NSObject : AnyObject])之后添加GAI.sharedInstance().dispatch() tracker.send(builder_event.build() as [NSObject : AnyObject])

Its been a while since I used GA but from memory I had a similar issue to this in the past. I think the issue was that it only handled integer values for the "value" field of an Event. So your interval being a float is probably the issue. Try explicitly using an Int, you can always just move the decimal point if you need(measure milliseconds).

As a side note, since you already have Firebase in your app. Is there a reason you aren't using Firebase Analytics instead of Google Analytics? In my experience its superior to GA for Mobile Analytics.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM