Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions examples/expo/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
trace,
error,
warn,
logScreenView,
} from '@bitdrift/react-native';
import axios from 'axios';
import { Picker } from '@react-native-picker/picker';
Expand Down Expand Up @@ -65,6 +66,8 @@ const HomeScreen = () => {
log?.(`[${selectedLogLevel.toUpperCase()}]: Log emitted`, {
randomNumber: Math.random(),
});

logScreenView('HomeScreen');
showToast(`Logged: [${selectedLogLevel.toUpperCase()}]: Log emitted`);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ class BdReactNativeModule internal constructor(context: ReactApplicationContext)
Capture.Logger.removeField(key)
}

@ReactMethod
override fun logScreenView(screenView: String) {
Capture.Logger.logScreenView(screenView)
}

companion object {
const val NAME = "BdReactNative"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ abstract class BdReactNativeSpec internal constructor(context: ReactApplicationC
abstract fun addField(key: String, value: String)

abstract fun removeField(key: String)

abstract fun logScreenView(screenView: String)
}
5 changes: 5 additions & 0 deletions packages/react-native/ios/BdReactNative.mm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ @implementation BdReactNative
[CAPRNLogger getSessionURL:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(logScreenView:(NSString *)screenName)
{
[CAPRNLogger logScreenViewWithScreenName:screenName];
}

#ifndef RCT_NEW_ARCH_ENABLED

RCT_EXPORT_METHOD(init:(NSString*)apiKey
Expand Down
5 changes: 5 additions & 0 deletions packages/react-native/ios/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ import Capture
}
resolve(sessionURL)
}

@objc
public static func logScreenView(screenName: String) {
Capture.Logger.logScreenView(screenName: screenName)
}
}
2 changes: 2 additions & 0 deletions packages/react-native/src/NativeBdReactNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export interface Spec extends TurboModule {
getSessionID(): Promise<string>;

getSessionURL(): Promise<string>;

logScreenView(screenName: string): void;
}

export default TurboModuleRegistry.getEnforcing<Spec>('BdReactNative');
8 changes: 8 additions & 0 deletions packages/react-native/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ export async function getSessionURL(): Promise<string> {
return NativeBdReactNative.getSessionURL();
}

/**
* Logs a screen view event. This can be called to record that a screen was viewed.
* @param screenName The name of the screen that was viewed.
*/
export function logScreenView(screenName: string): void {
return NativeBdReactNative.logScreenView(screenName);
}

/**
* Generate a device code for the current device. Useful for streaming logs from a specific device using {@link https://docs.bitdrift.dev/cli/quickstart.html#log-tailing|bd tail}.
* @returns The device code for the current device.
Expand Down