Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds an optional parameter for screen class in function setCurrentScr… #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ ___

### setCurrentScreen

**setCurrentScreen**(`screenName`): `Promise`<`void`\>
**setCurrentScreen**(`screenName`,`screenClass`): `Promise`<`void`\>

Sets the current screen name, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app.
Sets the current screen name and screen class, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app. Screen class is optional. If you don't provide a value for second parameter, screen class is automatically set as screen name.

**`Example`**

```ts
cordova.plugins.firebase.analytics.setCurrentScreen("User dashboard");
cordova.plugins.firebase.analytics.setCurrentScreen("User dashboard", "User dashboard");
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `screenName` | `string` | Current screen name |
| `screenClass` | `string` | Current screen class (optional) |

#### Returns

Expand Down
2 changes: 2 additions & 0 deletions src/android/FirebaseAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ protected void setEnabled(CordovaArgs args, CallbackContext callbackContext) thr
@CordovaMethod
protected void setCurrentScreen(CordovaArgs args, CallbackContext callbackContext) throws JSONException {
String screenName = args.getString(0);
String screenClass = args.getString(1);
Bundle bundle = new Bundle();
bundle.putString(FirebaseAnalytics.Param.SCREEN_NAME, screenName);
bundle.putString(FirebaseAnalytics.Param.SCREEN_CLASS, screenClass);
firebaseAnalytics.logEvent(FirebaseAnalytics.Event.SCREEN_VIEW, bundle);
callbackContext.success();
}
Expand Down
4 changes: 3 additions & 1 deletion src/ios/FirebaseAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ - (void)setEnabled:(CDVInvokedUrlCommand *)command {

- (void)setCurrentScreen:(CDVInvokedUrlCommand *)command {
NSString* screenName = [command.arguments objectAtIndex:0];
NSString* screenClass = [command.arguments objectAtIndex:1];

[FIRAnalytics logEventWithName:kFIREventScreenView parameters:@{
kFIRParameterScreenName: screenName
kFIRParameterScreenName: screenName,
kFIRParameterScreenClass: screenClass
}];

CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
Expand Down
8 changes: 5 additions & 3 deletions www/FirebaseAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ function(enabled) {

exports.setCurrentScreen =
/**
* Sets the current screen name, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app.
* Sets the current screen name and screen class, which specifies the current visual context in your app. This helps identify the areas in your app where users spend their time and how they interact with your app.
*
* @param {string} screenName Current screen name
* @param {string} screenClass Current screen class
* @returns {Promise<void>} Callback when operation is completed
*
* @example
* cordova.plugins.firebase.analytics.setCurrentScreen("User dashboard");
*/
function(screenName) {
function(screenName, screenClass) {
if(typeof screenClass == "undefined") screenClass = screenName;
return new Promise(function(resolve, reject) {
exec(resolve, reject, PLUGIN_NAME, "setCurrentScreen", [screenName]);
exec(resolve, reject, PLUGIN_NAME, "setCurrentScreen", [screenName, screenClass]);
});
};

Expand Down