Skip to content

Commit 962134c

Browse files
committed
set up sending screen events
1 parent 2178956 commit 962134c

File tree

4 files changed

+75
-24
lines changed

4 files changed

+75
-24
lines changed

example/App.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ const App = () => {
7575
>
7676
<Text>Reset</Text>
7777
</TouchableOpacity>
78+
<TouchableOpacity
79+
style={styles.button}
80+
onPress={() => {
81+
segmentClient.screen('Home Screen', { productId: 123 });
82+
}}
83+
>
84+
<Text>Send Screen</Text>
85+
</TouchableOpacity>
7886
</View>
7987
</ScrollView>
8088
</SafeAreaView>
@@ -84,6 +92,7 @@ const App = () => {
8492
const styles = StyleSheet.create({
8593
buttonContainer: {
8694
flexDirection: 'row',
95+
flexWrap: 'wrap',
8796
},
8897
button: {
8998
backgroundColor: 'gray',

src/FullStoryConfig.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
TrackEventType,
44
SegmentEvent,
55
Plugin,
6+
ScreenEventType,
67
} from '@segment/analytics-react-native';
78
import FullStory from '@fullstory/react-native';
89
import { FSSuffixedProperties } from './utils/FSSuffixedProperties';
@@ -12,19 +13,22 @@ interface FullStoryPluginConfig {
1213
allowlistAllTrackEvents?: boolean;
1314
allowlistTrackEvents?: Array<string>;
1415
enableIdentifyEvents?: boolean;
16+
enableSendScreenAsEvents?: boolean;
1517
}
1618

1719
const FULLSTORY_PLUGIN_CONFIG_DEFAULTS: FullStoryPluginConfig = {
1820
enableFSSessionUrlInEvents: true,
1921
allowlistAllTrackEvents: false,
2022
enableIdentifyEvents: true,
23+
enableSendScreenAsEvents: false,
2124
};
2225

2326
export class FullStoryPlugin extends Plugin {
2427
public enableFSSessionURLInEvents;
2528
public allowlistAllTrackEvents;
2629
public allowlistTrackEvents;
2730
public enableIdentifyEvents;
31+
public enableSendScreenAsEvents;
2832

2933
private fsSessionUrl = '';
3034

@@ -43,6 +47,7 @@ export class FullStoryPlugin extends Plugin {
4347
this.allowlistAllTrackEvents = config.allowlistAllTrackEvents;
4448
this.allowlistTrackEvents = config.allowlistTrackEvents;
4549
this.enableIdentifyEvents = config.enableIdentifyEvents;
50+
this.enableSendScreenAsEvents = config.enableSendScreenAsEvents;
4651
}
4752

4853
execute(event: SegmentEvent) {
@@ -66,6 +71,15 @@ export class FullStoryPlugin extends Plugin {
6671
FullStory.identify(event.userId || '', event.traits);
6772
}
6873
break;
74+
case 'screen':
75+
if (this.enableSendScreenAsEvents) {
76+
FullStory.event('Segment Screen: ' + event.name, event.properties);
77+
78+
if (this.enableFSSessionURLInEvents && this.fsSessionUrl) {
79+
this.addFSUrlToProperties(event as ScreenEventType);
80+
}
81+
}
82+
break;
6983
}
7084

7185
return event;
@@ -75,7 +89,7 @@ export class FullStoryPlugin extends Plugin {
7589
FullStory.anonymize();
7690
}
7791

78-
addFSUrlToProperties(event: TrackEventType) {
92+
addFSUrlToProperties(event: TrackEventType | ScreenEventType) {
7993
if (!event.properties) {
8094
event.properties = {};
8195
}

src/__tests__/FullStoryConfig.test.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
11
import { FullStoryPlugin } from '../FullStoryConfig';
2-
import {
3-
EventType,
4-
TrackEventType,
5-
IdentifyEventType,
6-
} from '@segment/analytics-react-native';
2+
import type { TrackEventType } from '@segment/analytics-react-native';
73
import FullStory from '@fullstory/react-native';
8-
9-
const EVENT_NAME = 'sample event';
10-
11-
const TRACK_EVENT: TrackEventType = {
12-
type: EventType.TrackEvent,
13-
event: EVENT_NAME,
14-
};
15-
16-
const IDENTIFY_EVENT: IdentifyEventType = {
17-
type: EventType.IdentifyEvent,
18-
};
4+
import {
5+
EVENT_NAME,
6+
identifyEvent,
7+
screenEvent,
8+
trackEvent,
9+
} from './__fixtures__/FSSampleEvents';
1910

2011
interface TrackEventTypeWIthFSUrl extends TrackEventType {
2112
properties: {
@@ -38,7 +29,7 @@ describe('FullStoryConfig', () => {
3829
await new Promise(process.nextTick);
3930

4031
const event = plugin.execute({
41-
...TRACK_EVENT,
32+
...trackEvent,
4233
}) as TrackEventTypeWIthFSUrl;
4334

4435
expect(event.properties.fullstoryUrl).toBe('sampleurl.com');
@@ -52,7 +43,7 @@ describe('FullStoryConfig', () => {
5243

5344
await new Promise(process.nextTick);
5445

55-
const event = plugin.execute({ ...TRACK_EVENT }) as TrackEventType;
46+
const event = plugin.execute({ ...trackEvent }) as TrackEventType;
5647

5748
expect(event.properties).toBe(undefined);
5849
});
@@ -65,7 +56,7 @@ describe('FullStoryConfig', () => {
6556
});
6657

6758
plugin.execute({
68-
...TRACK_EVENT,
59+
...trackEvent,
6960
});
7061

7162
expect(FullStory.event).not.toHaveBeenCalled();
@@ -77,7 +68,7 @@ describe('FullStoryConfig', () => {
7768
});
7869

7970
plugin.execute({
80-
...TRACK_EVENT,
71+
...trackEvent,
8172
});
8273

8374
expect(FullStory.event).toHaveBeenCalledTimes(1);
@@ -90,7 +81,7 @@ describe('FullStoryConfig', () => {
9081
});
9182

9283
plugin.execute({
93-
...TRACK_EVENT,
84+
...trackEvent,
9485
});
9586

9687
expect(FullStory.event).toHaveBeenCalledTimes(1);
@@ -104,7 +95,7 @@ describe('FullStoryConfig', () => {
10495
});
10596

10697
plugin.execute({
107-
...IDENTIFY_EVENT,
98+
...identifyEvent,
10899
});
109100

110101
expect(FullStory.identify).toHaveBeenCalledTimes(1);
@@ -116,7 +107,7 @@ describe('FullStoryConfig', () => {
116107
});
117108

118109
plugin.execute({
119-
...IDENTIFY_EVENT,
110+
...identifyEvent,
120111
});
121112

122113
expect(FullStory.identify).not.toHaveBeenCalled();
@@ -132,4 +123,16 @@ describe('FullStoryConfig', () => {
132123
expect(FullStory.anonymize).toHaveBeenCalledTimes(1);
133124
});
134125
});
126+
127+
describe('Test enableSendScreenAsEvents', () => {
128+
test('Should call FS event', () => {
129+
const plugin = new FullStoryPlugin({ enableSendScreenAsEvents: true });
130+
131+
plugin.execute({
132+
...screenEvent,
133+
});
134+
135+
expect(FullStory.event).toHaveBeenCalledTimes(1);
136+
});
137+
});
135138
});

src/__tests__/__fixtures__/FSSampleEvents.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import {
2+
EventType,
3+
TrackEventType,
4+
IdentifyEventType,
5+
ScreenEventType,
6+
} from '@segment/analytics-react-native';
7+
18
export const eCommerceEventsProductListFilteredRaw = {
29
list_id: 'todays_deals_may_11_2019',
310
filters: [
@@ -56,3 +63,21 @@ export const eCommerceEventsProductListFilteredProcessed = {
5663
'products.url_str': 'https://www.example.com/product/path',
5764
'products.image_url_str': 'https://www.example.com/product/path.jpg',
5865
};
66+
67+
export const EVENT_NAME = 'sample event';
68+
const SCREEN_NAME = 'sample screen';
69+
70+
export const trackEvent: TrackEventType = {
71+
type: EventType.TrackEvent,
72+
event: EVENT_NAME,
73+
};
74+
75+
export const identifyEvent: IdentifyEventType = {
76+
type: EventType.IdentifyEvent,
77+
};
78+
79+
export const screenEvent: ScreenEventType = {
80+
type: EventType.ScreenEvent,
81+
name: SCREEN_NAME,
82+
properties: {},
83+
};

0 commit comments

Comments
 (0)