
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
clevertap-cordova
Advanced tools
Tested on Cordova 6.1.1
To integrate CleverTap for Cordova:
Sign up
Set up and register for Push notifications, if required.
Integrate your Javascript with the CleverTap Plugin.
Sign up for a free account.
When you create your CleverTap account, you will also automatically get a -Test account. Use the -Test account for development and the main account for production.
Grab the Account ID and Token values from your CleverTap Dashboard -> Settings.
cordova plugin add https://github.com/CleverTap/clevertap-cordova.git --variable CLEVERTAP_ACCOUNT_ID=YOUR CLEVERTAP ACCOUNT ID --variable CLEVERTAP_TOKEN=YOUR CELVERTAP ACCOUNT TOKEN
cordova plugin add https://github.com/CleverTap/clevertap-cordova.git --variable CLEVERTAP_ACCOUNT_ID=YOUR CLEVERTAP ACCOUNT ID --variable CLEVERTAP_TOKEN=YOUR CELVERTAP ACCOUNT TOKEN --variable GCM_PROJECT_NUMBER=YOUR GCM PROJECT NUMBER
ionic plugin add https://github.com/CleverTap/clevertap-cordova.git --variable CLEVERTAP_ACCOUNT_ID=YOUR CLEVERTAP ACCOUNT ID --variable CLEVERTAP_TOKEN=YOUR CELVERTAP ACCOUNT TOKEN
ionic plugin add https://github.com/CleverTap/clevertap-cordova.git --variable CLEVERTAP_ACCOUNT_ID=YOUR CLEVERTAP ACCOUNT ID --variable CLEVERTAP_TOKEN=YOUR CELVERTAP ACCOUNT TOKEN --variable GCM_PROJECT_NUMBER=YOUR GCM PROJECT NUMBER
Add the following to your www/config.xml
file:
<preference name="android-build-tool" value="gradle" />
<gap:plugin name="clevertap-cordova" source="npm">
<param name="CLEVERTAP_ACCOUNT_ID" value="YOUR CLEVERTAP ACCOUNT ID" />
<param name="CLEVERTAP_TOKEN" value="YOUR CLEVERTAP ACCOUNT TOKEN" />
<param name="GCM_PROJECT_NUMBER" value="YOUR GCM PROJECT NUMBER" />
</gap:plugin>
For PhoneGap Build Android projects only: Extremely Important: add CleverTap.notifyDeviceReady();
to your onDeviceReady callback in www/js/index.js
:
onDeviceReady: function() {
app.receivedEvent('deviceready');
CleverTap.notifyDeviceReady();
...
},
Check your .plist file:
Check that the following is inside the <application></application>
tags of your AndroidManifest.xml:
<meta-data
android:name="CLEVERTAP_ACCOUNT_ID"
android:value="Your CleverTap Account ID"/>
<meta-data
android:name="CLEVERTAP_TOKEN"
android:value="Your CleverTap Account Token"/>
Replace "Your CleverTap Account ID" and "Your CleverTap Account Token" with actual values from your CleverTap Dashboard -> Settings.
Set the Lifecycle Callback
IMPORTANT!
Check the android:name
property of the <application>
tag of our AndroidManifest.xml:
<application
android:name="com.clevertap.android.sdk.Application">
Note: The above step is extremely important and enables CleverTap to track notification opens, display in-app notifications, track deep links, and other important user behaviour.
Add Permissions
Please ensure that you're requesting the following permissions for your app:
<!-- Required to retrieve a unique identifier for the device, see note below -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<!-- Required to allow the app to send events -->
<uses-permission android:name="android.permission.INTERNET"/>
<!-- Recommended so that we can be smart about when to send the data -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- Recommended so that we can get the user's primary e-mail address -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<!-- Recommended so that we can get the user's location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<!-- Recommended -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Please see the example AndroidManifest.xml here.
Add Dependencies
Make sure your build.gradle file includes the play-services and support library dependencies:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar' )
// SUB-PROJECT DEPENDENCIES START
debugCompile project(path: "CordovaLib", configuration: "debug")
releaseCompile project(path: "CordovaLib", configuration: "release")
compile "com.google.android.gms:play-services-base:+"
compile "com.google.android.gms:play-services-basement:+"
compile "com.google.android.gms:play-services-gcm:+"
compile "com.google.android.gms:play-services-location:+"
compile "com.android.support:support-v4:+"
// SUB-PROJECT DEPENDENCIES END
Follow Steps 1 and 2 in these instructions to set up push notifications for your app.
If you plan on including deep links in your push notifications, please register your custom url scheme as described here.
Afterwards, call the following from your Javascript.
CleverTap.registerPush();
To handle deep links contained in push notifications, you can pass the deep link url to your javascript by firing a custom document event from your AppDelegate application:openURL:sourceApplication: method. See the example below:
- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
{
if (!url) {
return NO;
}
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
// example Deep Link Handling
NSString *scheme = [url scheme];
if([scheme isEqualToString:@"<your custom url scheme>"]) {
NSString *js = [NSString stringWithFormat:@"cordova.fireDocumentEvent('onDeepLink', {'deeplink':'%@'});", url.description];
[self.viewController.commandDelegate evalJs:js];
}
return YES;
}
See the included example Starter Cordova project.
Follow these instructions to set up push notifications for your app.
To handle deep links contained in push notifications, you can pass the deep link url to your javascript by firing a custom document event from your MainActivity. See the example below:
Add the required intent filter to your MainActivity tag in AndroidManifest.xml:
<!-- Example Deep Link Handling, substitute your deeplink scheme for clevertapstarter -->
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="clevertapstarter" />
</intent-filter>
Handle the intent in your MainActivity.java:
// example deeplink handling
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (intent.getAction().equals(Intent.ACTION_VIEW)) {
Uri data = intent.getData();
if (data != null) {
final String json = "{'deeplink':'"+data.toString()+"'}";
loadUrl("javascript:cordova.fireDocumentEvent('onDeepLink'," + json + ");");
}
}
}
After integrating, all calls to the CleverTap SDK should be made from your Javascript.
Start by adding the following listeners to your Javascript:
document.addEventListener('deviceready', this.onDeviceReady, false);
document.addEventListener('onCleverTapProfileSync', this.onCleverTapProfileSync, false); // optional: to be notified of CleverTap user profile synchronization updates
document.addEventListener('onDeepLink', this.onDeepLink, false); // example: optional, register your own custom listener to handle deep links passed from your native code.
Then:
FAQs
CleverTap Plugin for Cordova/PhoneGap
The npm package clevertap-cordova receives a total of 276 weekly downloads. As such, clevertap-cordova popularity was classified as not popular.
We found that clevertap-cordova demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.