-
Notifications
You must be signed in to change notification settings - Fork 197
fix: add logic to convert traits to strings #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export const libraryInfo = { | ||
name: '@segment/analytics-react-native', | ||
version: '2.12.0', | ||
version: '2.13.0', | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,45 @@ import { | |
ScreenEventType, | ||
TrackEventType, | ||
} from '@segment/analytics-react-native'; | ||
import identify from './methods/identify'; | ||
import screen from './methods/screen'; | ||
import track from './methods/track'; | ||
import reset from './methods/reset'; | ||
import firebaseAnalytics from '@react-native-firebase/analytics'; | ||
|
||
export class FirebasePlugin extends DestinationPlugin { | ||
type = PluginType.destination; | ||
key = 'Firebase'; | ||
|
||
identify(event: IdentifyEventType) { | ||
identify(event); | ||
async identify(event: IdentifyEventType) { | ||
if (event.userId !== undefined) { | ||
await firebaseAnalytics().setUserId(event.userId!); | ||
} | ||
if (event.traits) { | ||
let eventTraits = event.traits; | ||
let safeTraits: Record<string, string>; | ||
|
||
const checkType = (value: unknown) => { | ||
return typeof value === 'object' && !Array.isArray(value); | ||
}; | ||
safeTraits = Object.keys(eventTraits).reduce( | ||
(acc: Record<string, string>, trait) => { | ||
if (checkType(eventTraits[trait])) { | ||
this.analytics?.logger.warn( | ||
'We detected an object or array data type. Firebase does not accept nested traits.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alanjcharles There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh yeah, nice catch! |
||
); | ||
|
||
return acc; | ||
} | ||
if (trait !== undefined) { | ||
acc[trait] = eventTraits[trait]!.toString(); | ||
} | ||
return acc; | ||
}, | ||
{} | ||
); | ||
|
||
await firebaseAnalytics().setUserProperties(safeTraits); | ||
} | ||
return event; | ||
} | ||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why make this a separate declaration? =)