From 9d86ca8d630f531c0321caa9aa12b3452f13fe25 Mon Sep 17 00:00:00 2001 From: vikramjo Date: Thu, 21 Mar 2024 09:21:40 -0400 Subject: [PATCH] Adds an optional parameter for screen class in function setCurrentScreen. Since it's optional, it shouldn't bother the people who don't want to change anything. Yet provides a way for those who want to have a more meaningful class names sent for analytics. --- README.md | 7 ++++--- src/android/FirebaseAnalyticsPlugin.java | 2 ++ src/ios/FirebaseAnalyticsPlugin.m | 4 +++- www/FirebaseAnalytics.js | 8 +++++--- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9580ebac..cb94efba 100644 --- a/README.md +++ b/README.md @@ -142,14 +142,14 @@ ___ ### 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 @@ -157,6 +157,7 @@ cordova.plugins.firebase.analytics.setCurrentScreen("User dashboard"); | Name | Type | Description | | :------ | :------ | :------ | | `screenName` | `string` | Current screen name | +| `screenClass` | `string` | Current screen class (optional) | #### Returns diff --git a/src/android/FirebaseAnalyticsPlugin.java b/src/android/FirebaseAnalyticsPlugin.java index ba07d3d1..9d9c030c 100644 --- a/src/android/FirebaseAnalyticsPlugin.java +++ b/src/android/FirebaseAnalyticsPlugin.java @@ -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(); } diff --git a/src/ios/FirebaseAnalyticsPlugin.m b/src/ios/FirebaseAnalyticsPlugin.m index 3612ceae..39815624 100644 --- a/src/ios/FirebaseAnalyticsPlugin.m +++ b/src/ios/FirebaseAnalyticsPlugin.m @@ -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]; diff --git a/www/FirebaseAnalytics.js b/www/FirebaseAnalytics.js index 0bb322ce..68c41c4f 100644 --- a/www/FirebaseAnalytics.js +++ b/www/FirebaseAnalytics.js @@ -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} 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]); }); };