Skip to content

Commit

Permalink
Implement setScreenName method for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelDeMartin committed Feb 3, 2017
1 parent c4951c0 commit 7f21e5f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ Log an event using Analytics:
window.FirebasePlugin.logEvent("page_view", {page: "dashboard"});
```

### setScreenName

Set the name of the current screen in Analytics:
```
window.FirebasePlugin.setScreenName("Home");
```

### setUserId

Set a user id for use in Analytics:
Expand Down
18 changes: 17 additions & 1 deletion src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public void run() {
FirebasePlugin.notificationStack = new ArrayList<Bundle>();
}
notificationStack.add(extras);

}
}
});
Expand Down Expand Up @@ -96,6 +95,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("logEvent")) {
this.logEvent(callbackContext, args.getString(0), args.getJSONObject(1));
return true;
} else if (action.equals("setScreenName")) {
this.setScreenName(callbackContext, args.getString(0));
return true;
} else if (action.equals("setUserId")) {
this.setUserId (callbackContext, args.getString(0));
return true;
Expand Down Expand Up @@ -339,6 +341,20 @@ public void run() {
});
}

private void setScreenName(final CallbackContext callbackContext, final String name) {
// This must be called on the main thread
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
try {
mFirebaseAnalytics.setCurrentScreen(cordova.getActivity(), name, null);
callbackContext.success();
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}

private void setUserId(final CallbackContext callbackContext, final String id) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Expand Down
6 changes: 6 additions & 0 deletions www/firebase-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ exports.logEvent = function(name, params, success, error) {
}
};

exports.setScreenName = function(name, success, error) {
if (typeof success === 'function') {
success();
}
};

exports.setUserId = function(id, success, error) {
if (typeof success === 'function') {
success();
Expand Down
6 changes: 5 additions & 1 deletion www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.grantPermission = function(success, error) {
exports.hasPermission = function(success, error) {
exec(success, error, "FirebasePlugin", "hasPermission", []);
};

exports.setBadgeNumber = function(number, success, error) {
exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]);
};
Expand All @@ -44,6 +44,10 @@ exports.logEvent = function(name, params, success, error) {
exec(success, error, "FirebasePlugin", "logEvent", [name, params]);
};

exports.setScreenName = function(name, success, error) {
exec(success, error, "FirebasePlugin", "setScreenName", [name]);
};

exports.setUserId = function(id, success, error) {
exec(success, error, "FirebasePlugin", "setUserId", [id]);
};
Expand Down

0 comments on commit 7f21e5f

Please sign in to comment.