Viewlytics
Import the SDK
import Viewlytics from 'react-native-viewlytics';
Methods
Viewlytics.init(sdkKey: string)
Initializes the Viewlytics SDK with the provided SDK key.
This method should be called once at the start of your application, typically in the main entry point file (e.g., App.js
or index.js
).
- Parameters:
sdkKey
(type:string
) - Your unique SDK key obtained from the Viewlytics dashboard. - Returns:
void
Viewlytics.init('your-sdk-key');
Viewlytics.captureScreen(eventName: string)
Captures a screenshot of the current screen and sends it to the Viewlytics server. The screenshot is associated with the provided event name, which helps categorize and filter screenshots in the Viewlytics dashboard.
- Parameters:
eventName
(type:string
) - A name to identify the event associated with the screenshot. - Returns:
void
Viewlytics.captureScreen('your_event_name');
Viewlytics.setUserId(userId: string)
Sets the user ID for the current session. This method allows you to associate screenshots with specific users, enabling better tracking and analysis of user behavior.
- Parameters:
userId
(type:string
) - The unique identifier for the user. - Returns:
void
Viewlytics.setUserId('user_id_123');
Viewlytics.setUserMetadata(userMetadata: object)
Sets custom user metadata for the current session. This method allows you to attach additional metadata to the user, which can be useful for filtering and analyzing screenshots in the Viewlytics dashboard.
- Parameters:
userMetadata
(type:Record<string, any>
) - An object containing key-value pairs of custom metadata. - Returns:
void
Viewlytics.setUserMetadata({
age: 25, // Example age value
});
Viewlytics.getUserId()
Retrieves the current user ID.
- Parameters: None
- Returns:
string | null
- The user ID if set, otherwisenull
.
const userId = Viewlytics.getUserId();
Viewlytics.getUserMetadata()
Retrieves the current user metadata.
- Parameters: None
- Returns:
Record<string, any>
- The user metadata object.
const metadata = Viewlytics.getUserMetadata();
Viewlytics.getSDKKey()
Retrieves the currently stored SDK key.
- Parameters: None
- Returns:
string
- The SDK key. - Throws:
Error
if the SDK key is not set.
try {
const sdkKey = Viewlytics.getSDKKey();
} catch (error) {
console.error(error.message); // SDK key is not set. Please initialize the SDK first.
}