Skip to content

Commit

Permalink
feat: add option to disable screen view usage (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shahroz16 authored Jan 6, 2025
2 parents 1be1c0e + c5b7829 commit 055835e
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 97 deletions.
88 changes: 44 additions & 44 deletions Apps/APN/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ PODS:
- JSONSafeEncoding (= 2.0.0)
- Sovran (= 1.1.1)
- boost (1.83.0)
- customerio-reactnative (4.1.0):
- customerio-reactnative/nopush (= 4.1.0)
- CustomerIO/DataPipelines (= 3.6.0)
- CustomerIO/MessagingInApp (= 3.6.0)
- customerio-reactnative (4.1.1):
- customerio-reactnative/nopush (= 4.1.1)
- CustomerIO/DataPipelines (= 3.7.1)
- CustomerIO/MessagingInApp (= 3.7.1)
- React-Core
- customerio-reactnative-richpush/apn (4.1.0):
- CustomerIO/MessagingPushAPN (= 3.6.0)
- customerio-reactnative/apn (4.1.0):
- CustomerIO/DataPipelines (= 3.6.0)
- CustomerIO/MessagingInApp (= 3.6.0)
- CustomerIO/MessagingPushAPN (= 3.6.0)
- customerio-reactnative-richpush/apn (4.1.1):
- CustomerIO/MessagingPushAPN (= 3.7.1)
- customerio-reactnative/apn (4.1.1):
- CustomerIO/DataPipelines (= 3.7.1)
- CustomerIO/MessagingInApp (= 3.7.1)
- CustomerIO/MessagingPushAPN (= 3.7.1)
- React-Core
- customerio-reactnative/nopush (4.1.0):
- CustomerIO/DataPipelines (= 3.6.0)
- CustomerIO/MessagingInApp (= 3.6.0)
- CustomerIO/MessagingPush (= 3.6.0)
- customerio-reactnative/nopush (4.1.1):
- CustomerIO/DataPipelines (= 3.7.1)
- CustomerIO/MessagingInApp (= 3.7.1)
- CustomerIO/MessagingPush (= 3.7.1)
- React-Core
- CustomerIO/DataPipelines (3.6.0):
- CustomerIODataPipelines (= 3.6.0)
- CustomerIO/MessagingInApp (3.6.0):
- CustomerIOMessagingInApp (= 3.6.0)
- CustomerIO/MessagingPush (3.6.0):
- CustomerIOMessagingPush (= 3.6.0)
- CustomerIO/MessagingPushAPN (3.6.0):
- CustomerIOMessagingPushAPN (= 3.6.0)
- CustomerIOCommon (3.6.0)
- CustomerIODataPipelines (3.6.0):
- CustomerIO/DataPipelines (3.7.1):
- CustomerIODataPipelines (= 3.7.1)
- CustomerIO/MessagingInApp (3.7.1):
- CustomerIOMessagingInApp (= 3.7.1)
- CustomerIO/MessagingPush (3.7.1):
- CustomerIOMessagingPush (= 3.7.1)
- CustomerIO/MessagingPushAPN (3.7.1):
- CustomerIOMessagingPushAPN (= 3.7.1)
- CustomerIOCommon (3.7.1)
- CustomerIODataPipelines (3.7.1):
- "AnalyticsSwiftCIO (= 1.5.14+cio.1)"
- CustomerIOCommon (= 3.6.0)
- CustomerIOTrackingMigration (= 3.6.0)
- CustomerIOMessagingInApp (3.6.0):
- CustomerIOCommon (= 3.6.0)
- CustomerIOMessagingPush (3.6.0):
- CustomerIOCommon (= 3.6.0)
- CustomerIOMessagingPushAPN (3.6.0):
- CustomerIOMessagingPush (= 3.6.0)
- CustomerIOTrackingMigration (3.6.0):
- CustomerIOCommon (= 3.6.0)
- CustomerIOCommon (= 3.7.1)
- CustomerIOTrackingMigration (= 3.7.1)
- CustomerIOMessagingInApp (3.7.1):
- CustomerIOCommon (= 3.7.1)
- CustomerIOMessagingPush (3.7.1):
- CustomerIOCommon (= 3.7.1)
- CustomerIOMessagingPushAPN (3.7.1):
- CustomerIOMessagingPush (= 3.7.1)
- CustomerIOTrackingMigration (3.7.1):
- CustomerIOCommon (= 3.7.1)
- DoubleConversion (1.1.6)
- FBLazyVector (0.73.6)
- FBReactNativeSpec (0.73.6):
Expand Down Expand Up @@ -1327,15 +1327,15 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AnalyticsSwiftCIO: d03712b33e85baecc86f0d38a6d53c97f7bc5bd1
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
CustomerIO: 6b1af81928a0302d884f116295b7e8610636e809
customerio-reactnative: dce3adb93dea0dfb775e1c6682b141e02fefcb77
customerio-reactnative-richpush: e55473741f992fb56f42d41128b26f82c4ec4f91
CustomerIOCommon: b33c69e670c2a9295750e20fe1c70282fc0a223f
CustomerIODataPipelines: 2de3237d302176d282d0d9dbc208410921bda351
CustomerIOMessagingInApp: d53ad8cc06551cc1a4e65be038470c061597c22a
CustomerIOMessagingPush: 2eb6db3a2edcbb679f314fd0431f86c5fe2fefbf
CustomerIOMessagingPushAPN: 00d4593f6a0b740c4841cdebe4cbfce3e8a718a2
CustomerIOTrackingMigration: 5b0dbdf3d5f3eaa6bb15e4827a7557e1e0ba826f
CustomerIO: f533d422104faa98489b84231b56a76452a82ebd
customerio-reactnative: 162d471ca6fac8a1b179999d89b7abafd06c0f9d
customerio-reactnative-richpush: ca8609621beca08bf81d7f402b38b3e2f0c251ac
CustomerIOCommon: 0e8447fe53a0806e296cef18c812b7d7af9e1911
CustomerIODataPipelines: ba5fe9a196bbed151e01943268c27c664f1aa703
CustomerIOMessagingInApp: e6cf21470898f7468d6e1976d5dfac81e63353e3
CustomerIOMessagingPush: 63f03aaa13ffcf6489b49ac63e49fa4d6ffe2ade
CustomerIOMessagingPushAPN: 592e128a2a6a3c5a51f8b283519f3ecdfb9fe6e7
CustomerIOTrackingMigration: d2d1d5e30adb81bd439f46c08647ba761c759f64
DoubleConversion: fea03f2699887d960129cc54bba7e52542b6f953
FBLazyVector: f64d1e2ea739b4d8f7e4740cde18089cd97fe864
FBReactNativeSpec: 9f2b8b243131565335437dba74923a8d3015e780
Expand Down Expand Up @@ -1400,4 +1400,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 4fd33e739b5364991c8ac49c0c56e7b4a80e4c02

COCOAPODS: 1.16.2
COCOAPODS: 1.15.2
4 changes: 2 additions & 2 deletions Apps/APN/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Apps/APN/src/data/sdk/CustomerIoSDKConfig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ScreenView } from 'customerio-reactnative';
import Env from '../../../env';

export default class CustomerIoSDKConfig {
Expand All @@ -6,6 +7,7 @@ export default class CustomerIoSDKConfig {
cdpApiKey,
flushInterval,
flushAt,
screenViewUse,
trackScreens,
trackDeviceAttributes,
debugMode,
Expand All @@ -15,6 +17,7 @@ export default class CustomerIoSDKConfig {
this.cdpApiKey = cdpApiKey;
this.flushInterval = flushInterval;
this.flushAt = flushAt;
this.screenViewUse = screenViewUse;
this.trackAppLifecycleEvents = trackAppLifecycleEvents;
this.trackScreens = trackScreens;
this.trackDeviceAttributes = trackDeviceAttributes;
Expand All @@ -29,6 +32,7 @@ export default class CustomerIoSDKConfig {
trackDeviceAttributes: true,
trackAppLifecycleEvents: true,
debugMode: true,
screenViewUse: ScreenView.All.toString(),
});
}

Expand All @@ -43,6 +47,7 @@ export default class CustomerIoSDKConfig {
debugMode: other?.debugMode ?? defaultConfig.debugMode,
trackAppLifecycleEvents:
other?.trackAppLifecycleEvents ?? defaultConfig.trackAppLifecycleEvents,
screenViewUse: other?.screenViewUse ?? defaultConfig.screenViewUse,
});
}
}
59 changes: 58 additions & 1 deletion Apps/APN/src/screens/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ScrollView,
StyleSheet,

Check warning on line 15 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L15

[no-unused-vars] 'StyleSheet' is defined but never used.
View,
TouchableOpacity,
} from 'react-native';
import { FilledButton, TextButton } from '../components/Button';
import { SwitchField } from '../components/SwitchField';
Expand All @@ -25,7 +26,7 @@ import { useCustomerIoSdkContext } from '../state/customerIoSdkState';
import { useUserStateContext } from '../state/userState';
import { resetRoute } from '../utils/navigation';
import Prompts from '../utils/prompts';
import { CustomerIO } from 'customerio-reactnative';
import { CustomerIO, ScreenView } from 'customerio-reactnative';

const Settings = ({ navigation, route }) => {
const { params } = route;
Expand Down Expand Up @@ -57,6 +58,8 @@ const Settings = ({ navigation, route }) => {
return false;
}, [navigation, user]);

const [screenView, setScreenView] = useState(ScreenView.All.toString());

useLayoutEffect(() => {
if (!navigation.canGoBack()) {
navigation.setOptions({
Expand Down Expand Up @@ -98,6 +101,7 @@ const Settings = ({ navigation, route }) => {
setTrackScreensEnabled(initialConfig.trackScreens);
setTrackDeviceAttributesEnabled(initialConfig.trackDeviceAttributes);
setDebugModeEnabled(initialConfig.debugMode);
setScreenView(initialConfig.screenViewUse);
setAppLifecycleEventTrackingEnabled(initialConfig?.trackAppLifecycleEvents);
}, [initialCdpApiKey, initialConfig, initialSiteId]);

Expand Down Expand Up @@ -137,6 +141,7 @@ const Settings = ({ navigation, route }) => {
config.trackDeviceAttributes = isTrackDeviceAttributesEnabled;
config.debugMode = isDebugModeEnabled;
config.trackAppLifecycleEvents = isAppLifecycleEventTrackingEnabled;
config.screenViewUse = screenView;
saveConfigurations(config);
navigation.goBack();
};
Expand Down Expand Up @@ -238,6 +243,58 @@ const Settings = ({ navigation, route }) => {
contentDesc="Debug Mode Toggle"
/>
</View>
<View style={settingsStyles.section}>
<Text style={settingsStyles.sectionLabel}>ScreenView Use</Text>
<View
style={[
settingsStyles.buttonGroup,
{ backgroundColor: '#F0F0F5', borderRadius: 8 },

Check warning on line 251 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L251

[react-native/no-inline-styles] Inline style: { backgroundColor: '#F0F0F5', borderRadius: 8 }
]}
>
<TouchableOpacity
style={[
settingsStyles.segmentButton,
{ flex: 1 },

Check warning on line 257 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L257

[react-native/no-inline-styles] Inline style: { flex: 1 }
screenView === ScreenView.All.toString() && {
backgroundColor: '#4B48C9',
},

Check warning on line 260 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L258-L260

[react-native/no-inline-styles] Inline style: { backgroundColor: '#4B48C9' }
]}
onPress={() => setScreenView(ScreenView.All.toString())}
>
<Text
style={[
settingsStyles.segmentButtonText,
screenView === ScreenView.All.toString() && {
color: 'white',
},

Check warning on line 269 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L267-L269

[react-native/no-inline-styles] Inline style: { color: 'white' }
]}
>
All
</Text>
</TouchableOpacity>
<TouchableOpacity
style={[
settingsStyles.segmentButton,
{ flex: 1 },

Check warning on line 278 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L278

[react-native/no-inline-styles] Inline style: { flex: 1 }
screenView === ScreenView.InApp.toString() && {
backgroundColor: '#4B48C9',
},

Check warning on line 281 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L279-L281

[react-native/no-inline-styles] Inline style: { backgroundColor: '#4B48C9' }
]}
onPress={() => setScreenView(ScreenView.InApp.toString())}
>
<Text
style={[
settingsStyles.segmentButtonText,
screenView === ScreenView.InApp.toString() && {
color: 'white',
},

Check warning on line 290 in Apps/APN/src/screens/Settings.js

View workflow job for this annotation

GitHub Actions / eslint results

Apps/APN/src/screens/Settings.js#L288-L290

[react-native/no-inline-styles] Inline style: { color: 'white' }
]}
>
InApp
</Text>
</TouchableOpacity>
</View>
</View>
<View style={settingsStyles.buttonContainer}>
<FilledButton
style={settingsStyles.saveButton}
Expand Down
10 changes: 10 additions & 0 deletions Apps/APN/src/services/CustomerIOService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ import {
CustomerIO,
CioLogLevel,
InAppMessageEventType,
ScreenView,
} from 'customerio-reactnative';

const stringToScreenView = (str) => {
if (str.toLowerCase() === ScreenView.InApp.toString().toLowerCase()) {
return ScreenView.InApp;
}
return ScreenView.All;
};

export const initializeCustomerIoSDK = (sdkConfig) => {
let screenViewUse = stringToScreenView(sdkConfig.screenViewUse);
const config = {
cdpApiKey: sdkConfig.cdpApiKey, // Mandatory
migrationSiteId: sdkConfig.siteId, // For migration
trackApplicationLifecycleEvents: sdkConfig.trackAppLifecycleEvents,
autoTrackDeviceAttributes: sdkConfig.autoTrackDeviceAttributes,
screenViewUse: screenViewUse,
inApp: {
siteId: sdkConfig.siteId,
},
Expand Down
17 changes: 17 additions & 0 deletions Apps/APN/src/styles/stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ export const styles = StyleSheet.create({
note: {
marginTop: 8,
},
buttonGroup: {
flexDirection: 'row',
marginVertical: 8,
padding: 4,
},
segmentButton: {
paddingVertical: 8,
paddingHorizontal: 16,
borderRadius: 6,
alignItems: 'center',
justifyContent: 'center',
},
segmentButtonText: {
fontSize: 16,
fontWeight: '500',
color: '#666666',
},
});
Loading

0 comments on commit 055835e

Please sign in to comment.