[analytics] Add additional validation
This commit is contained in:
parent
213f03737b
commit
e3ea0d3fc7
|
@ -122,7 +122,12 @@ export default class Analytics extends ModuleBase {
|
||||||
* Sets the user ID property.
|
* Sets the user ID property.
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
setUserId(id: string): void {
|
setUserId(id: string | null): void {
|
||||||
|
if (id !== null && !isString(id)) {
|
||||||
|
throw new Error(
|
||||||
|
'analytics.setUserId(): The supplied userId must be a string value or null.'
|
||||||
|
);
|
||||||
|
}
|
||||||
getNativeModule(this).setUserId(id);
|
getNativeModule(this).setUserId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,17 +136,28 @@ export default class Analytics extends ModuleBase {
|
||||||
* @param name
|
* @param name
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
setUserProperty(name: string, value: string): void {
|
setUserProperty(name: string, value: string | null): void {
|
||||||
|
if (value !== null && !isString(value)) {
|
||||||
|
throw new Error(
|
||||||
|
'analytics.setUserProperty(): The supplied property must be a string value or null.'
|
||||||
|
);
|
||||||
|
}
|
||||||
getNativeModule(this).setUserProperty(name, value);
|
getNativeModule(this).setUserProperty(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a user property to a given value.
|
* Sets multiple user properties to the supplied values.
|
||||||
* @RNFirebaseSpecific
|
* @RNFirebaseSpecific
|
||||||
* @param object
|
* @param object
|
||||||
*/
|
*/
|
||||||
setUserProperties(object: Object): void {
|
setUserProperties(object: Object): void {
|
||||||
Object.keys(object).forEach(property => {
|
Object.keys(object).forEach(property => {
|
||||||
|
const value = object[property];
|
||||||
|
if (value !== null && !isString(value)) {
|
||||||
|
throw new Error(
|
||||||
|
`analytics.setUserProperties(): The property with name '${property}' must be a string value or null.`
|
||||||
|
);
|
||||||
|
}
|
||||||
getNativeModule(this).setUserProperty(property, object[property]);
|
getNativeModule(this).setUserProperty(property, object[property]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue