Skip to content

Commit bf9828f

Browse files
committed
feat: integrate demo app with react-native Sourcepoint SDK
1 parent e09731b commit bf9828f

File tree

8 files changed

+120
-11
lines changed

8 files changed

+120
-11
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules/
22
lib/
3+
ios/
4+
android/

example/ios/ContentpassExample/PrivacyInfo.xcprivacy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
<array>
77
<dict>
88
<key>NSPrivacyAccessedAPIType</key>
9-
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
9+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
1010
<key>NSPrivacyAccessedAPITypeReasons</key>
1111
<array>
12-
<string>C617.1</string>
12+
<string>CA92.1</string>
1313
</array>
1414
</dict>
1515
<dict>
1616
<key>NSPrivacyAccessedAPIType</key>
17-
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
17+
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
1818
<key>NSPrivacyAccessedAPITypeReasons</key>
1919
<array>
20-
<string>CA92.1</string>
20+
<string>C617.1</string>
2121
</array>
2222
</dict>
2323
<dict>

example/ios/Podfile.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PODS:
66
- AppAuth/ExternalUserAgent (1.7.5):
77
- AppAuth/Core
88
- boost (1.84.0)
9+
- ConsentViewController (7.6.7):
10+
- Down (~> 0.11.0)
911
- DoubleConversion (1.1.6)
1012
- FBLazyVector (0.76.2)
1113
- fmt (9.1.0)
@@ -1542,6 +1544,28 @@ PODS:
15421544
- React-perflogger (= 0.76.2)
15431545
- React-utils (= 0.76.2)
15441546
- SocketRocket (0.7.1)
1547+
- sourcepoint-react-native-cmp (0.3.0):
1548+
- ConsentViewController (= 7.6.7)
1549+
- DoubleConversion
1550+
- glog
1551+
- hermes-engine
1552+
- RCT-Folly (= 2024.01.01.00)
1553+
- RCTRequired
1554+
- RCTTypeSafety
1555+
- React-Core
1556+
- React-debug
1557+
- React-Fabric
1558+
- React-featureflags
1559+
- React-graphics
1560+
- React-ImageManager
1561+
- React-NativeModulesApple
1562+
- React-RCTFabric
1563+
- React-rendererdebug
1564+
- React-utils
1565+
- ReactCodegen
1566+
- ReactCommon/turbomodule/bridging
1567+
- ReactCommon/turbomodule/core
1568+
- Yoga
15451569
- Yoga (0.0.0)
15461570

15471571
DEPENDENCIES:
@@ -1612,11 +1636,13 @@ DEPENDENCIES:
16121636
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
16131637
- ReactCodegen (from `build/generated/ios`)
16141638
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
1639+
- "sourcepoint-react-native-cmp (from `../node_modules/@sourcepoint/react-native-cmp`)"
16151640
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
16161641

16171642
SPEC REPOS:
16181643
trunk:
16191644
- AppAuth
1645+
- ConsentViewController
16201646
- SocketRocket
16211647

16221648
EXTERNAL SOURCES:
@@ -1751,12 +1777,15 @@ EXTERNAL SOURCES:
17511777
:path: build/generated/ios
17521778
ReactCommon:
17531779
:path: "../node_modules/react-native/ReactCommon"
1780+
sourcepoint-react-native-cmp:
1781+
:path: "../node_modules/@sourcepoint/react-native-cmp"
17541782
Yoga:
17551783
:path: "../node_modules/react-native/ReactCommon/yoga"
17561784

17571785
SPEC CHECKSUMS:
17581786
AppAuth: 501c04eda8a8d11f179dbe8637b7a91bb7e5d2fa
17591787
boost: 1dca942403ed9342f98334bf4c3621f011aa7946
1788+
ConsentViewController: 243f7bfcde4b6ec71a5033486465b7c17448493c
17601789
DoubleConversion: f16ae600a246532c4020132d54af21d0ddb2a385
17611790
FBLazyVector: bc70dcb22ad30ce734a7cce7210791dc737e230f
17621791
fmt: 10c6e61f4be25dc963c36bd73fc7b1705fe975be
@@ -1822,6 +1851,7 @@ SPEC CHECKSUMS:
18221851
ReactCodegen: 93b271af49774429f34d7fd561197020d86436e2
18231852
ReactCommon: 208cb02e3c0bb8a727b3e1a1782202bcfa5d9631
18241853
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
1854+
sourcepoint-react-native-cmp: 895d48d036184268872955c4df25bb3bd44c2266
18251855
Yoga: 96872ee462cfc43866ad013c8160d4ff6b85709b
18261856

18271857
PODFILE CHECKSUM: c50a131c6dd5a8e1657bf6b76ff12413d914b88e

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"build:ios": "react-native build-ios --scheme ContentpassExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\""
1111
},
1212
"dependencies": {
13+
"@sourcepoint/react-native-cmp": "^0.3.0",
1314
"react": "18.3.1",
1415
"react-native": "0.76.2",
1516
"react-native-app-auth": "^8.0.0",

example/src/ContentpassUsage.tsx

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,84 @@
11
import { useContentpassSdk } from './ContentpassContext';
2-
import { Button, Text } from 'react-native';
3-
import { useState } from 'react';
2+
import { Button, ScrollView, StyleSheet, Text, View } from 'react-native';
3+
import { useEffect, useRef, useState } from 'react';
44
import type { AuthenticateResult } from 'react-native-contentpass';
5+
import {
6+
SPConsentManager,
7+
type SPUserData,
8+
} from '@sourcepoint/react-native-cmp';
9+
10+
const styles = StyleSheet.create({
11+
sourcepointDataContainer: {
12+
padding: 10,
13+
height: 400,
14+
flexGrow: 0,
15+
},
16+
});
17+
18+
const sourcePointConfig = {
19+
accountId: 375,
20+
propertyId: 37858,
21+
propertyName: 'mobile.cmpsourcepoint.demo',
22+
};
523

624
export default function ContentpassUsage() {
725
const [authResult, setAuthResult] = useState<
826
AuthenticateResult | undefined
927
>();
1028
const contentpassSdk = useContentpassSdk();
29+
const consentManager = useRef<SPConsentManager | null>();
30+
const [sourcepointUserData, setSourcepointUserData] = useState<
31+
SPUserData | undefined
32+
>();
33+
34+
useEffect(() => {
35+
const { accountId, propertyName, propertyId } = sourcePointConfig;
36+
consentManager.current = new SPConsentManager();
37+
consentManager.current?.build(accountId, propertyId, propertyName, {
38+
gdpr: {
39+
targetingParams: {
40+
acps: authResult?.hasValidSubscription ? 'true' : 'false',
41+
},
42+
},
43+
});
44+
45+
consentManager.current?.onFinished(() => {
46+
consentManager.current?.getUserData().then(setSourcepointUserData);
47+
});
48+
49+
consentManager.current?.loadMessage();
50+
51+
return () => {
52+
try {
53+
consentManager.current?.dispose();
54+
} catch (err) {
55+
// FIXME: contact sourcepoint as dispose method sometimes crashes app
56+
}
57+
};
58+
}, [authResult]);
1159

1260
const authenticate = async () => {
1361
const result = await contentpassSdk.authenticate();
1462
setAuthResult(result);
1563
};
1664

65+
const clearSourcepointData = () => {
66+
consentManager.current?.clearLocalData();
67+
setSourcepointUserData(undefined);
68+
};
69+
1770
return (
1871
<>
1972
<Button title={'Authenticate'} onPress={authenticate} />
20-
<Text>Result: {JSON.stringify(authResult)}</Text>
73+
<Button title={'Clear sourcepoint data'} onPress={clearSourcepointData} />
74+
<View style={{ marginTop: 10 }}>
75+
<Text>Authenticate result:</Text>
76+
<Text>{JSON.stringify(authResult, null, 2)}</Text>
77+
<Text>Sourcepoint user data:</Text>
78+
<ScrollView style={styles.sourcepointDataContainer}>
79+
<Text>{JSON.stringify(sourcepointUserData, null, 2)}</Text>
80+
</ScrollView>
81+
</View>
2182
</>
2283
);
2384
}

jest.config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"preset": "react-native",
33
"modulePathIgnorePatterns": [
4-
",<rootDir>/example/node_modules",
5-
"<rootDir>/lib/"
4+
"./example/node_modules",
5+
"./ib/",
6+
"./ios/",
7+
"./android/"
68
]
79
}
810

turbo.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"$schema": "https://turbo.build/schema.json",
33
"pipeline": {
44
"build:android": {
5-
"env": ["ORG_GRADLE_PROJECT_newArchEnabled"],
5+
// We had to disable the new architecture because @sourcepoint/react-native-cmp doesn;t support it
6+
// "env": ["ORG_GRADLE_PROJECT_newArchEnabled"],
67
"inputs": [
78
"package.json",
89
"android",
@@ -18,7 +19,8 @@
1819
"outputs": []
1920
},
2021
"build:ios": {
21-
"env": ["RCT_NEW_ARCH_ENABLED"],
22+
// We had to disable the new architecture because @sourcepoint/react-native-cmp doesn;t support it
23+
// "env": ["RCT_NEW_ARCH_ENABLED"],
2224
"inputs": [
2325
"package.json",
2426
"*.podspec",

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,6 +2990,16 @@ __metadata:
29902990
languageName: node
29912991
linkType: hard
29922992

2993+
"@sourcepoint/react-native-cmp@npm:^0.3.0":
2994+
version: 0.3.0
2995+
resolution: "@sourcepoint/react-native-cmp@npm:0.3.0"
2996+
peerDependencies:
2997+
react: "*"
2998+
react-native: "*"
2999+
checksum: dc41dc065a0ab54a87cfbd03fae4a78923904585eff2b9d6cedea35a1b662c5ee61ea0178af2121de3819afa995fbdf712503629a4e0189e822b9291e3dd42ba
3000+
languageName: node
3001+
linkType: hard
3002+
29933003
"@tootallnate/quickjs-emscripten@npm:^0.23.0":
29943004
version: 0.23.0
29953005
resolution: "@tootallnate/quickjs-emscripten@npm:0.23.0"
@@ -10585,6 +10595,7 @@ __metadata:
1058510595
"@react-native/babel-preset": 0.76.2
1058610596
"@react-native/metro-config": 0.76.2
1058710597
"@react-native/typescript-config": 0.76.2
10598+
"@sourcepoint/react-native-cmp": ^0.3.0
1058810599
react: 18.3.1
1058910600
react-native: 0.76.2
1059010601
react-native-app-auth: ^8.0.0

0 commit comments

Comments
 (0)