Skip to main content
Version: React Native SDK

Examples

Practical, task-based code snippets for the React Native SDK.

Basic setupโ€‹

If the user is already authenticated when the app loads, pass their identity directly to initSdk() to avoid creating an anonymous user:

import { initSdk } from "@screeb/react-native";

React.useEffect(() => {
initSdk("<YOUR-CHANNEL-ID>", "<USER-ID>", {
email: "support@screeb.app",
plan: "pro",
});
}, []);

If the user isn't authenticated yet, init without identity and call setIdentity() after login (see below).

React.useEffect(() => {
initSdk("<YOUR-CHANNEL-ID>");
}, []);

Identify a user after loginโ€‹

When a user logs in post-init, identify them:

import { setIdentity } from "@screeb/react-native";

setIdentity("user-123", {
email: "support@screeb.app",
plan: "premium",
signup_date: new Date("2024-01-15"),
});

Track an eventโ€‹

Track user actions with optional properties for context:

import { trackEvent } from "@screeb/react-native";

// Simple event
trackEvent("button_clicked");

// Event with properties
trackEvent("checkout_completed", {
amount: 99.99,
currency: "USD",
items_count: 3,
payment_method: "credit_card",
});

Start a surveyโ€‹

Trigger a survey programmatically when a user performs an action:

import { startSurvey } from "@screeb/react-native";

// Start a specific survey
startSurvey("<SURVEY-ID>");

// Prevent multiple responses
startSurvey("<SURVEY-ID>", false);

// Add hidden fields for context
startSurvey("<SURVEY-ID>", true, {
source: "checkout_page",
cart_value: 149.99,
});

Use hooksโ€‹

Set up hooks during initialization to react to survey events:

import { initSdk } from "@screeb/react-native";

React.useEffect(() => {
initSdk(
"<YOUR-CHANNEL-ID>",
"user-123",
{
email: "support@screeb.app",
},
{
version: "1.0.0",
onReady: (payload) => {
console.log("Screeb SDK is ready", payload);
},
onSurveyCompleted: (payload) => {
console.log("Survey completed", payload);
// Track completion in your analytics
// Show a thank you message
},
onSurveyDisplayAllowed: (payload) => {
console.log("Survey about to display", payload);
// Return false to prevent display
return true;
},
}
);
}, []);

Reset on logoutโ€‹

Clear the current user identity when they log out:

import { resetIdentity } from "@screeb/react-native";

const handleLogout = () => {
// Clear user session
resetIdentity();
// Navigate to login screen
};