fix(Amplitude): user id

This commit is contained in:
Hristo Terezov 2019-05-29 16:24:50 +01:00
parent fecbef0aff
commit 9712804040
4 changed files with 30 additions and 1 deletions

View File

@ -52,6 +52,17 @@ class AmplitudeModule
Amplitude.getInstance(instanceName).initialize(getCurrentActivity(), apiKey);
}
/**
* Sets the user ID for an Amplitude instance.
*
* @param instanceName The name of the Amplitude instance.
* @param userId The new value for the user ID.
*/
@ReactMethod
public void setUserId(String instanceName, String userId) {
Amplitude.getInstance(instanceName).setUserId(userId);
}
/**
* Sets the user properties for an Amplitude instance.
*

View File

@ -33,6 +33,10 @@ RCT_EXPORT_METHOD(init:(NSString*)instanceName API_KEY:(NSString*)apiKey) {
[[Amplitude instanceWithName:instanceName] initializeApiKey:apiKey];
}
RCT_EXPORT_METHOD(setUserId:(NSString*)instanceName userId: (NSString *) userId) {
[[Amplitude instanceWithName:instanceName] setUserId:userId];
}
RCT_EXPORT_METHOD(setUserProperties:(NSString*)instanceName userPropsString:(NSDictionary*)userProps) {
if (userProps != nil) {
[[Amplitude instanceWithName:instanceName] setUserProperties:userProps];

View File

@ -15,7 +15,7 @@ export default class AmplitudeHandler extends AbstractHandler {
constructor(options) {
super();
const { amplitudeAPPKey, host } = options;
const { amplitudeAPPKey, host, user } = options;
if (!amplitudeAPPKey) {
throw new Error('Failed to initialize Amplitude handler, no APP key');
@ -28,6 +28,10 @@ export default class AmplitudeHandler extends AbstractHandler {
};
amplitude.getInstance(this._amplitudeOptions).init(amplitudeAPPKey);
if (user) {
amplitude.getInstance(this._amplitudeOptions).setUserId(user);
}
}
/**

View File

@ -31,6 +31,16 @@ class Amplitude {
AmplitudeNative.init(this._instanceName, apiKey);
}
/**
* Sets an identifier for the current user.
*
* @param {string} userId - The new user id.
* @returns {void}
*/
setUserId(userId) {
AmplitudeNative.setUserId(this._instanceName, userId);
}
/**
* Sets user properties for the current user.
*