React Native SDK
This is a step by step guide to include Conscent.ai package in your app. This package is developed in TypeScript and JavaScript.
yourClientId
Pass your clientId received from Conscent.ai
yourContentId
Unique id of each content
scroll-Y
Pass the scroll depth of your content screen
userAgent
Pass userAgent of your device
Mode
Mode can be set as :
STAGING
SANDBOX
LIVE
Initialize the paywall
Define these states on the content screen
const [scrollY, setScrollY] = useState(0);
const paywallRef = useRef(null);
const [showPaywall, setShowPaywall] = useState(true);
const [showContent, setShowContent] = useState(false);
const [mode, setMode] = useState('SANDBOX');
Call the Paywall on top of your content screen
import PayWall, { getEventsEnvDetails, pageExist, onTouchListener, PopUp } from 'csc-react-native-sdk';
const userAgent = await DeviceInfo.getUserAgent();
useFocusEffect(
React.useCallback(() => {
return () => {
removePage();
};
}, [])
);
async function removePage() {
const res = await pageExist(getEventsEnvDetails(mode), clientId, contentId)
}
const conscentMessage = async (message) => {
if (message == 'GoogleLoginClick') {
googleSignIn();
}
}
const googleSignIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
const email = userInfo.user.email;
const data = await genrateTempToken(email, mode);
const tempToken = data?.tempAuthToken;
await autoLoginView(tempToken, clientId, email, phoneNumber, currentStackScreenName, props.navigation, mode); // phoneNumber optional(pass empty string)
} catch (error) {
console.log('got error: ', error.message);
}
}
async function onStatusChange(result) {
if (result?.successMessage == 'METERBANNER') {
setShowPaywall(true);
setShowContent(true);
}
else if (result?.successMessage == 'PAYWALL') {
setShowPaywall(true);
setShowContent(false);
}
else if (result?.successMessage == 'UNLOCK') {
setShowPaywall(false);
setShowContent(true);
}
}
const goBack = () => {
// Go back to the previous screen
props?.navigation.goBack();
}
return (
<SafeAreaView style={styles.container}>
<ScrollView
onScroll={(e) => {
setScrollY(e.nativeEvent.contentOffset.y)
// call this method when user do any activity on screen
onTouchListener();
}}>
{
showContent ?
<Text>{ showContent your full content }</Text> : <Text>{ showContent your locked content }</Text>
}
</ScrollView>
{userAgent && showPaywall &&
<PayWall
ref={paywallRef}
clientId={clientId}
contentId={contentId}
environment={mode}
userAgent={userAgent}
conscentMessage={conscentMessage}
onPaywallStatus={(result) => {
onStatusChange(result)
}}
onErrorMessage={(error) => {
console.log('Error', error)
}}
navigation={props?.navigation}
scrollY={scrollY}
goBack={() => {
goBack()
}} />
}
<PopUp
environment={mode}
currentStackName={'Your_current_stack_name'}
navigation={props?.navigation}
scrollY={scrollY}
/>
</SafeAreaView >
)
call removePage() in useFocusEffect
call onTouchListener() : when the user does any activity on the screen
Paywall Listener
Implement the onStatusChange method in your component
METERBANNER: when receiving it then unlock content and show the paywall
PAYWALL: when receiving it then lock the content and show the paywall
UNLOCK: when receiving it then unlock the content and don't show the paywall
Demo app Link
Last updated