Skip to content
Open
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
8 changes: 4 additions & 4 deletions packages/plugins/plugin-firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
},
"homepage": "https://github.com/segmentio/analytics-react-native/tree/master/packages/plugins/plugin-firebase#readme",
"peerDependencies": {
"@react-native-firebase/analytics": ">=18.4.0",
"@react-native-firebase/app": ">=18.4.0",
"@react-native-firebase/analytics": ">=22.2.0",
"@react-native-firebase/app": ">=22.2.0",
"@segment/analytics-react-native": "^2.18.0"
},
"devDependencies": {
"@react-native-firebase/analytics": "^18.4.0",
"@react-native-firebase/app": "^18.4.0",
"@react-native-firebase/analytics": "^22.2.0",
"@react-native-firebase/app": "^22.2.0",
"@segment/analytics-react-native": "^2.18.0",
"@segment/analytics-rn-shared": "workspace:^",
"@segment/sovran-react-native": "^1.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/plugin-firebase/src/FirebasePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import {
import screen from './methods/screen';
import track from './methods/track';
import reset from './methods/reset';
import firebaseAnalytics from '@react-native-firebase/analytics';
import { firebaseAnalytics } from './firebaseAnalytics';
export class FirebasePlugin extends DestinationPlugin {
type = PluginType.destination;
key = 'Firebase';

async identify(event: IdentifyEventType) {
if (event.userId !== undefined) {
await firebaseAnalytics().setUserId(event.userId);
await firebaseAnalytics.setUserId(event.userId);
}
if (event.traits) {
const eventTraits = event.traits;
Expand Down Expand Up @@ -45,7 +45,7 @@ export class FirebasePlugin extends DestinationPlugin {
{}
);

await firebaseAnalytics().setUserProperties(safeTraits);
await firebaseAnalytics.setUserProperties(safeTraits);
}
return event;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/plugin-firebase/src/firebaseAnalytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { getAnalytics } from '@react-native-firebase/analytics';
import { getApp } from '@react-native-firebase/app';

export const firebaseAnalytics = getAnalytics(getApp());
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import type { IdentifyEventType } from '@segment/analytics-react-native';
import { FirebasePlugin } from '../../FirebasePlugin';

const mockSetUserId = jest.fn();
const mockSetUserProperties = jest.fn();

jest.mock('@react-native-firebase/analytics', () => () => ({
setUserId: mockSetUserId,
setUserProperties: mockSetUserProperties,
jest.mock('@react-native-firebase/analytics', () => ({
getAnalytics: jest.fn().mockImplementation(() => ({
setUserId: mockSetUserId,
setUserProperties: mockSetUserProperties,
})),
isString: (a: unknown) => typeof a === 'string',
}));
jest.mock('@react-native-firebase/app', () => ({
getApp: jest.fn(),
}));

import type { IdentifyEventType } from '@segment/analytics-react-native';
import { FirebasePlugin } from '../../FirebasePlugin';

describe('#identify', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import reset from '../reset';

const mockReset = jest.fn();

jest.mock('@react-native-firebase/analytics', () => () => ({
resetAnalyticsData: mockReset,
jest.mock('@react-native-firebase/analytics', () => ({
getAnalytics: jest.fn().mockImplementation(() => ({
resetAnalyticsData: mockReset,
})),
}));

jest.mock('@react-native-firebase/app', () => ({
getApp: jest.fn(),
}));

import reset from '../reset';

describe('#reset', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import type { ScreenEventType } from '@segment/analytics-react-native';
import screen from '../screen';

const mockScreen = jest.fn();

jest.mock('@react-native-firebase/analytics', () => () => ({
logScreenView: mockScreen,
jest.mock('@react-native-firebase/analytics', () => ({
getAnalytics: jest.fn().mockImplementation(() => ({
logScreenView: mockScreen,
})),
}));

jest.mock('@react-native-firebase/app', () => ({
getApp: jest.fn(),
}));

import type { ScreenEventType } from '@segment/analytics-react-native';
import screen from '../screen';

describe('#screen', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { EventType, TrackEventType } from '@segment/analytics-react-native';
import track from '../track';

jest.mock('uuid');

const mockLogEvent = jest.fn();

jest.mock('@react-native-firebase/analytics', () => () => ({
logEvent: mockLogEvent,
jest.mock('@react-native-firebase/analytics', () => ({
getAnalytics: jest.fn().mockImplementation(() => ({
logEvent: mockLogEvent,
})),
isString: (a: unknown) => typeof a === 'string',
}));
jest.mock('@react-native-firebase/app', () => ({
getApp: jest.fn(),
}));
jest.mock('uuid');

import { EventType, TrackEventType } from '@segment/analytics-react-native';
import track from '../track';

describe('#track', () => {
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/plugin-firebase/src/methods/reset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import firebaseAnalytics from '@react-native-firebase/analytics';
import { firebaseAnalytics } from '../firebaseAnalytics';

export default async () => {
await firebaseAnalytics().resetAnalyticsData();
await firebaseAnalytics.resetAnalyticsData();
};
4 changes: 2 additions & 2 deletions packages/plugins/plugin-firebase/src/methods/screen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import firebaseAnalytics from '@react-native-firebase/analytics';
import type { ScreenEventType } from '@segment/analytics-react-native';
import { firebaseAnalytics } from '../firebaseAnalytics';

export default async (event: ScreenEventType) => {
const screenProps = {
Expand All @@ -8,5 +8,5 @@ export default async (event: ScreenEventType) => {
...event.properties,
};

await firebaseAnalytics().logScreenView(screenProps);
await firebaseAnalytics.logScreenView(screenProps);
};
6 changes: 3 additions & 3 deletions packages/plugins/plugin-firebase/src/methods/track.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import firebaseAnalytics from '@react-native-firebase/analytics';
import {
type TrackEventType,
generateMapTransform,
TrackEventType,
} from '@segment/analytics-react-native';
import { firebaseAnalytics } from '../firebaseAnalytics';
import { mapEventProps, transformMap } from './parameterMapping';

const mappedPropNames = generateMapTransform(mapEventProps, transformMap);
Expand All @@ -22,5 +22,5 @@ export default async (event: TrackEventType) => {
if (safeEventName.length > 40) {
safeEventName = safeEventName.substring(0, 40);
}
await firebaseAnalytics().logEvent(safeEventName, safeProps);
await firebaseAnalytics.logEvent(safeEventName, safeProps);
};
Loading