Android
This is a step by step guide to include Conscent.ai Plugin in your app. This plugin is developed in Kotlin and supports both Java and Kotlin languages.
Pre-Requisites
Conscent.ai Android SDK supports API 21 (Android 5.0) and above. Please ensure the minSdkVersion is in the app's build.gradle file reflects the same.
In case of an error for Kotlin not enabled - Enable Kotlin for Project.
In case of an error in Manifest merging - Merge Manifest as per Android Studio support or include the below line inside your application tag in the Android Manifest file.
Permissions
Add the following permissions to the AndroidManifest.xml
file.
Pass the client ID received from Conscent.ai dashboard
Initialize the paywall
In order to ensure that the Conscent.ai Paywall appears on the targeted pages and the deep insights and analytics are collected optimally you need to implement the following method on all the content/article pages.
To have more control over the content flow, create an instance of the Conscent class inside your activity onCreate method for each unique contentId(recommended).
Use the below-described method:
Note: Include the AAR files of respective paywalls and banners before calling above functions.
To set the scroll depth on the content page:
Call the below sample method on override onActivityResult in Activity Class.
In case of Fragment, call the below method inside onDestoyView()-
yourCallingActivity(Activity)
This is your activity content which is calling the methods and where callback will be received.
yourParentView(ConstraintLayout)
This will be the parent of your layout. Please keep ConstraintLayout as your root view in your activity xml file. Pass the reference of your root view in checkContent function.
yourContainerView(FrameLayout)
This will be a FrameLayout where the payment page will be inflated. Create a frameLayout in your XML and pass it here as a reference.
For eg:
contentId (String)
This will be your article or content id for which detail needs to be checked.
yourContentTitle (String
- Optional)
Title of the content for display purposes.
yourSubsUrl (String
- Optional)
Url is to be used when subscribe button is clicked.
canSubscribe (Boolean
- Optional)
Pass this as "true" to show subscribe layout else as "false".
showClose (Boolean
- Optional)
Pass this as "true" to show the close button on the paywall/subscriptions, the default value is "false"
OnConscentListener
You can pass a listener which will get called after success or failure in processing. If you pass a listener, after successful processing, the success reference will be called and for a failed event, the failure event will be called
You can implement OnConscentListener in your activity and then pass it as a reference.
onSuccess
This is the success callback that will get called for every successful processing. You can pass your method as a reference or a lambda expression which will get called in case of success.
onError (optional)
You can pass it as null. This is the failure callback which will get called for every failed processing. You can pass your method as a reference or a lambda expression and it'll get called for failed cases. You can implement your code in it for failed cases.
onSubscribe (optional)
If you want to inflate subscribe layout, pass a subscribe function which will be called when subscribe button will be clicked inside the payment flow. Passing null will not inflate subscribe layout.
onBuyPass (optional)
It will be called when the buy-pass button will be clicked inside the payment flow.
onSignIn
This is the callback function that will be called when a user clicks on signIn button in the payment flow. This will be only visible if subscribe layout has been inflated.
onAdFree
This is the callback function which will be called when a user clicks on adfree subscription.
eventParams
This callback function will be called when a user clicks on the Google login. This will send params paywallId,contentId, paywallType, clientId, and anonId.
onShowPaywall
This callback function will be called when a paywall is visible on the screen. This will send params - eventLocation, eventType, paywallDisplayType, paywallType.
onGoogleLoginClick
This will be used to trigger your Google sign. This callback function will be called when a user clicks on the Google login.
onCustomLinkSlot
This will be triggered when the Link Slot To on the Conscent Dashboard is linked to Custom URL
To check if an article/content is free/paid or payment needs to be done, in your class, use as below sample: Parameters detail can be checked below for more information.
Call checkContentAccess method on override onNewIntent method in Activity Class.
Call the below function and pass the userId, after the user has logged in:
To use only the Subscription Landing Page, call the below method:
Create a singleton instance as done during initialization of the paywall.
Logout the User:
Demo App: Link
Last updated