简体   繁体   中英

How can I track a user with Google Analytics and Parse.IO?

I'm trying to find out how I can track users in Google Analytics and Parse through some sort of ID that I can use both on GA and Parse. For example: In my Parse browser I can go to the Users table and see users that register every day on my app. Each user is assigned an ObjectID in Parse. I would like to use this objectID and match the user with its Behavior analytic in GA. Is ObjectID the way to do this? Can I use GA's Client Id to find a user in Parse? Is there a better method for this?

My purpose for doing this is that I want to be able to look up a user in my Parse browser, look at his/her ClientID so I can then track that user's behavior with GA'S behavior analytics.

I think the best is to use objectId because it's unique identifier and this is exactly what you need. If you want you can also create your own unique id and store in an additional field of the user but I don't see any reason to do it. ObjectId can give you what you need and also it's good because you can do quick query from parse DB since it is a unique index

To store your GA Client ID in parse please use the following code:

Android version

    ParseUser currentUser = ParseUser.getCurrentUser();
    currentUser.put("GAClientId","{YOUR_GA_CLIENT_ID}");
    currentUser.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {

        }
    });

IOS Swift version

    let user = PFUser.currentUser()
    user?.setObject("{YOUR_GA_CLIENT_ID}", forKey: "GAClientId")
    user?.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError?) -> Void in

    })

JavaScript Version

var user = Parse.User.current();
user.set("GAClientID","{YOUR_GA_CLIENT_ID}");
user.save().then(function(){
    // success callback
},function(err){
    // error callback
});

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