11import { useContentpassSdk } from './ContentpassContext' ;
2- import { Button , Text } from 'react-native' ;
3- import { useState } from 'react' ;
2+ import { Button , ScrollView , StyleSheet , Text } from 'react-native' ;
3+ import { useEffect , useRef , useState } from 'react' ;
44import type { AuthenticateResult } from 'react-native-contentpass' ;
5+ import {
6+ type SPCampaigns ,
7+ SPConsentManager ,
8+ type SPUserData ,
9+ } from '@sourcepoint/react-native-cmp' ;
10+
11+ const styles = StyleSheet . create ( {
12+ sourcepointDataContainer : {
13+ padding : 10 ,
14+ height : 400 ,
15+ flexGrow : 0 ,
16+ } ,
17+ } ) ;
18+
19+ // FIXME: use own sourcepoint config
20+ const sourcePointConfig = {
21+ accountId : 22 , //375
22+ propertyId : 16893 , // 37858
23+ propertyName : 'mobile.multicampaign.demo' , // 'mobile.cmpsourcepoint.demo'
24+ campaigns : {
25+ gdpr : { } ,
26+ } as SPCampaigns ,
27+ } ;
528
629export default function ContentpassUsage ( ) {
730 const [ authResult , setAuthResult ] = useState <
831 AuthenticateResult | undefined
932 > ( ) ;
1033 const contentpassSdk = useContentpassSdk ( ) ;
34+ const consentManager = useRef < SPConsentManager | null > ( ) ;
35+ const [ sourcepointUserData , setSourcepointUserData ] = useState <
36+ SPUserData | undefined
37+ > ( ) ;
38+
39+ useEffect ( ( ) => {
40+ const { accountId, propertyName, propertyId, campaigns } =
41+ sourcePointConfig ;
42+ consentManager . current = new SPConsentManager ( ) ;
43+ consentManager . current ?. build (
44+ accountId ,
45+ propertyId ,
46+ propertyName ,
47+ campaigns
48+ ) ;
49+
50+ consentManager . current ?. onFinished ( ( ) => {
51+ consentManager . current ?. getUserData ( ) . then ( setSourcepointUserData ) ;
52+ } ) ;
53+
54+ consentManager . current ?. loadMessage ( ) ;
55+
56+ return ( ) => {
57+ consentManager . current ?. dispose ( ) ;
58+ } ;
59+ } , [ ] ) ;
1160
1261 const authenticate = async ( ) => {
1362 const result = await contentpassSdk . authenticate ( ) ;
@@ -17,7 +66,12 @@ export default function ContentpassUsage() {
1766 return (
1867 < >
1968 < Button title = { 'Authenticate' } onPress = { authenticate } />
20- < Text > Result: { JSON . stringify ( authResult ) } </ Text >
69+ < Text > Authenticate result:</ Text >
70+ < Text > { JSON . stringify ( authResult , null , 2 ) } </ Text >
71+ < Text > Sourcepoint user data:</ Text >
72+ < ScrollView style = { styles . sourcepointDataContainer } >
73+ < Text > { JSON . stringify ( sourcepointUserData , null , 2 ) } </ Text >
74+ </ ScrollView >
2175 </ >
2276 ) ;
2377}
0 commit comments