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

feat(analytics): add 'logScreenView' API and deprecate setCurrentScreen API. #4145

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions docs/analytics/screen-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import { NavigationContainer } from '@react-navigation/native';

<NavigationContainer
ref={navigationRef}
onStateChange={state => {
onStateChange={async (state) => {
const previousRouteName = routeNameRef.current;
const currentRouteName = getActiveRouteName(state);

if (previousRouteName !== currentRouteName) {
analytics().logScreenView({
await analytics().logScreenView({
screen_name: currentRouteName,
});
}
Expand All @@ -46,9 +46,9 @@ for React Native apps. To manually track screens, you need to setup a `component
import analytics from '@react-native-firebase/analytics';
import { Navigation } from 'react-native-navigation';

Navigation.events().registerComponentDidAppearListener(({ componentName, componentType }) => {
Navigation.events().registerComponentDidAppearListener(async ({ componentName, componentType }) => {
if (componentType === 'Component') {
analytics().logScreenView({
await analytics().logScreenView({
screen_name: componentName,
screen_class: componentName,
});
Expand Down
20 changes: 20 additions & 0 deletions packages/analytics/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,26 @@ export namespace FirebaseAnalyticsTypes {
* @param enabled A boolean value representing whether Analytics collection is enabled or disabled. Analytics collection is enabled by default.
*/
setAnalyticsCollectionEnabled(enabled: boolean): Promise<void>;

/**
* Sets the current screen name.
*
* #### Example
*
* ```js
* await firebase.analytics().setCurrentScreen('ProductScreen', 'ProductScreen');
* ```
*
* > Whilst screenClassOverride is optional, it is recommended it is
* always sent as your current class name. For example on Android it will always
* show as 'MainActivity' if you do not specify it.
*
* @param screenName A screen name, e.g. Product.
* @param screenClassOverride On Android, React Native runs in a single activity called
* @deprecated
* 'MainActivity'. Setting this parameter overrides the default name shown on logs.
russellwheatley marked this conversation as resolved.
Show resolved Hide resolved
*/
setCurrentScreen(screenName: string, screenClassOverride?: string): Promise<void>;
/**
* Sets the minimum engagement time required before starting a session.
*
Expand Down
6 changes: 5 additions & 1 deletion packages/analytics/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ class FirebaseAnalyticsModule extends FirebaseModule {
return this.native.setAnalyticsCollectionEnabled(enabled);
}

setCurrentScreen() {
setCurrentScreen(screenName, screenClassOverride) {
console.warn(
russellwheatley marked this conversation as resolved.
Show resolved Hide resolved
'firebase.analytics().setCurrentScreen(), is now deprecated. Please use firebase.analytics().logScreenView() instead',
);
return this.logScreenView({
screen_name: screenName,
screen_class: screenClassOverride,
});
}

setMinimumSessionDuration(milliseconds = 10000) {
Expand Down