Configuration¶
The Logger needs to be started before it can be used. Note that the start method only needs to be called once and will cause the Logger to retain this configuration until the end of the process. Subsequent calls to the start method won't have any effect.
The minimum required configuration of the SDK is as follows:
import io.bitdrift.capture.Capture.Logger
import io.bitdrift.capture.providers.session.SessionStrategy
Logger.start(
apiKey = "<your-api-key>",
sessionStrategy = SessionStrategy.Fixed,
)
Initialization¶
The Android SDK handles its initial configuration using Jetpack Startup. It uses an Initializer called ContextHolder to get a reference to the application's Context.
Initialization Dependency¶
If you wish to start the Logger from inside your own Initializer make sure to add it as a dependency:
import io.bitdrift.capture.ContextHolder
class AppExampleInitializer : Initializer<AppExampleDependency> {
override fun create(context: Context): AppExampleDependency {
// You can call Capture.Logger.start() here safely
return AppExampleDependency()
}
override fun dependencies(): List<Class<out Initializer<*>>> {
// Defines a dependency on ContextHolder so it can be
// initialized after bitdrift Capture is initialized.
return listOf(ContextHolder::class.java)
}
}
Manual Initialization¶
If you wish to avoid automatic initialization and want to manually call the bitdrift Capture initializer you can follow the steps below.
Add this to your AndroidManifest.xml configuration to disable automatic initialization:
<application>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge"
>
<!-- Disable automatic initialization of Bitdrift ContextHolder -->
<meta-data
android:name="io.bitdrift.capture.ContextHolder"
tools:node="remove"
/>
</provider>
</application>
Manually call the bitdrift initializer:
import io.bitdrift.capture.ContextHolder
// This needs to run before calling Logger.start()
AppInitializer.getInstance(applicationContext)
.initializeComponent(ContextHolder::class.java)
import io.bitdrift.capture.Capture.Logger;
import io.bitdrift.capture.providers.session.SessionStrategy;
Logger.start(
"<your-api-key>",
new SessionStrategy.Fixed()
);
Initialization¶
The Android SDK handles its initial configuration using Jetpack Startup[^1]. It uses an Initializer called ContextHolder to get a reference to the application's Context.
Initialization Dependency¶
If you wish to start the Logger from inside your own Initializer make sure to add it as a dependency:
import io.bitdrift.capture.ContextHolder;
class AppExampleInitializer implements Initializer<AppExampleDependency> {
@Override
public AppExampleDependency create(context: Context) {
// You can call Capture.Logger.start() here safely
return new AppExampleDependency();
}
@Override
public List<Class<Initializer<?>>> dependencies() {
// Defines a dependency on ContextHolder so it can be
// initialized after bitdrift Capture is initialized.
return Arrays.asList(ContextHolder.class);
}
}
Manual Initialization¶
If you wish to avoid automatic initialization and want to manually call the bitdrift Capture initializer you can follow the steps below.
Add this to your AndroidManifest.xml configuration to disable automatic initialization:
<application>
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge"
>
<!-- Disable automatic initialization of Bitdrift ContextHolder -->
<meta-data
android:name="io.bitdrift.capture.ContextHolder"
tools:node="remove"
/>
</provider>
</application>
Manually call the bitdrift initializer:
import io.bitdrift.capture.ContextHolder;
// This needs to run before calling Logger.start()
AppInitializer.getInstance(context)
.initializeComponent(ContextHolder.class);
import Capture
Logger.start(
withAPIKey: "<your-api-key>",
sessionStrategy: .fixed()
)
Info
It's recommended that you initialize the SDK as part of your application's application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:) methods. This allows the SDK to observe system events such as didFinishLaunchingNotification, which power some of the SDK's out-of-the-box events.
#import <Capture/Capture.h>
[CAPLogger
startWithAPIKey:@"your-api-key"
sessionStrategy: [CAPSessionStrategy fixed]
];
Info
It's recommended that you initialize the SDK as part of your application's application(_:willFinishLaunchingWithOptions:) or application(_:didFinishLaunchingWithOptions:) methods. This allows the SDK to observe system events such as didFinishLaunchingNotification, which power some of the SDK's out-of-the-box events.
When using the JavaScript-based initialization (e.g. using Expo), the SDK can be initialized as follows:
import { init, SessionStrategy } from '@bitdrift/react-native';
init("<your-api-key>", SessionStrategy.Fixed);
When using the native initialization (e.g. ejected Expo, non-Expo React Native), the SDK can be initialized using the per platform instructions above.
import { init, SessionStrategy } from '@bitdrift/react-native';
init("<your-api-key>", SessionStrategy.Fixed);
The SDK should be initialized in the main process.
See the Quickstart Guide section for information on how to obtain an API Key.