Skip to content

Analytics screenView snippet #191

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

Merged
merged 11 commits into from
Aug 10, 2021
16 changes: 16 additions & 0 deletions analytics-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,19 @@ function setUserProperties() {
setUserProperties(analytics, { favorite_food: 'apples' });
// [END analytics_set_user_properties]
}

function recordScreenView() {
const screenName = '<SCREEN_NAME>';

// [START analytics_record_screen_view]
const { getAnalytics, logEvent } = require("firebase/analytics");

const analytics = getAnalytics();
logEvent(analytics, 'screen_view', {
app_name: 'My App',
screen_name: screenName,
firebase_screen: screenName,
firebase_screen_class: 'Home'
});
// [END analytics_record_screen_view]
}
11 changes: 11 additions & 0 deletions analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ function setUserProperties() {
firebase.analytics().setUserProperties({favorite_food: 'apples'});
// [END analytics_set_user_properties]
}

function recordScreenView() {
const screenName = '<SCREEN_NAME>';

// [START analytics_record_screen_view]
firebase.analytics().logEvent('screen_view', {
'firebase_screen': screenName,
'firebase_screen_class': 'Home'
});
// [END analytics_record_screen_view]
}
14 changes: 14 additions & 0 deletions snippets/analytics-next/index/analytics_record_screen_view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This snippet file was generated by processing the source file:
// ./analytics-next/index.js
//
// To make edits to the snippets in this file, please edit the source

// [START analytics_record_screen_view_modular]
import { getAnalytics, logEvent } from "firebase/analytics";

const analytics = getAnalytics();
logEvent(analytics, 'screen_view', {
'firebase_screen': screenName,
'firebase_screen_class': 'Home'
});
// [END analytics_record_screen_view_modular]