https://github.com/webengage/cordova-plugin
Cordova/PhoneGap plugin for integrating WebEngage's native SDKs with hybrid Cordova/PhoneGap platforms
https://github.com/webengage/cordova-plugin
Last synced: about 1 year ago
JSON representation
Cordova/PhoneGap plugin for integrating WebEngage's native SDKs with hybrid Cordova/PhoneGap platforms
- Host: GitHub
- URL: https://github.com/webengage/cordova-plugin
- Owner: WebEngage
- Created: 2017-03-03T14:46:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T11:53:05.000Z (almost 2 years ago)
- Last Synced: 2025-04-11T23:16:44.623Z (about 1 year ago)
- Language: Objective-C
- Size: 461 KB
- Stars: 1
- Watchers: 5
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WebEngage Plugin for Cordova/Phonegap
The Cordova SDK was tested on Cordova v8.0.0 for Cordova android ^7.0.0 and Cordova iOS ^4.5.5. Read the complete documentation at [WebEngage Cordova/PhoneGap Plugin Documentation](http://docs.webengage.com/docs/cordova-integration)
## Installation
```
cordova plugin add cordova-plugin-webengage --fetch
```
## Integration
Add the following details in your `config.xml` file.
```xml
...
...
...
YOUR-LICENSE-CODE
<.platform>
```
**Note:** Replace 'YOUR-LICENSE-CODE' with your WebEngage License Code.
## Initialization
Initialize WebEngage SDK in your `wwww/js/index.js` file.
```javascript
var app = {
...
onDeviceReady: function() {
...
// WebEngage initialization
webengage.engage();
}
}
```
## Configurations
### 1. Enable/Disable SDK Logs
Add the following tags in your `config.xml` file.
```xml
...
...
...
VERBOSE
```
**Note:** Supported values for 'WEGLogLevel': 'VERBOSE', 'DEFAULT'.
### 2. Location Tracking
Add the following tags in your `config.xml` file.
```xml
...
...
...
...
location
```
## Tracking Users
You can set user attributes as shown in below example.
```javascript
// User login
webengage.user.login("user-id");
// User logout
webengage.user.logout();
// Set system user attributes
webengage.user.setAttribute("we_first_name", "John");
webengage.user.setAttribute("we_last_name", "Doe");
webengage.user.setAttribute("we_email", "john.doe@gmail.com");
webengage.user.setAttribute("we_birth_date", "1986-08-19");
webengage.user.setAttribute("we_phone", "+551155256325");
webengage.user.setAttribute("we_gender", "male"); // Supported values: 'male', 'female', 'other'
webengage.user.setAttribute("we_company", "Alphabet Inc.");
webengage.user.setAttribute("we_hashed_email", "144e0424883546e07dcd727057fd3b62");
webengage.user.setAttribute("we_hashed_phone", "e0ec043b3f9e198ec09041687e4d4e8d");
// Set custom user attributes
webengage.user.setAttribute("Category", "GOLD");
webengage.user.setAttribute("Value Index", 5.06);
webengage.user.setAttribute("Inactive", false);
webengage.user.setAttribute("Registered On", new Date("2015-11-09T10:01:11.000Z"));
```
**Note:** WebEngage SDK only supports the following data-types: String, Number, Boolean and Date.
## Tracking Events
You can track events as shown in the following example.
```javascript
// Simple event
webengage.track("Added to cart");
// Event with attributes
webengage.track("Purchased", {"product-id": "123", "product-name": "wrist-watch", "product-price": 25.65});
```
**Note:** WebEngage SDK only supports the following data-types: String, Number, Boolean and Date.
## Push Notifications
### 1. Android Push Notification Integration
#### FCM Integration
**1. Add this plugin to your Cordova project.**
```
cordova plugin add https://github.com/WebEngage/cordova-plugin-android-fcm.git --fetch
```
**2. Add google-services.json file.**
Follow the steps at [Android FCM Documentation](https://firebase.google.com/docs/android/setup) to get the google-services.json file from Firebase Cloud.
Save google-services.json file in the root of your project directory.
**3. Update FCM token on app launch.**
Send FCM token to WebEngage SDK in your `wwww/js/index.js` file.
```javascript
var app = {
...
onDeviceReady: function() {
...
androidfcm.updateToken();
}
}
```
Done. Run and test push notifications from WebEngage dashboard on your Android app.
#### GCM Integration (Deprecated)
Add the following in your `config.xml` file, under android platform tag.
```xml
...
...
...
...
```
**Note:** Replace the value of android.project_number with your GCM/FCM Project Number (Sender ID).
#### GCM to FCM Migration
1. Follow the [FCM Integration steps](https://github.com/WebEngage/cordova-plugin#fcm-integration).
2. Remove the following from your `config.xml` file, under android platform tag.
```xml
...
...
...
...
```
### 2. iOS Push Notification Integration
Enable 'Push Notifications' under capabilities tab in your XCode and then add 'WEGApnsAutoRegister' to info.plist with value true in `config.xml` file as shown below.
```xml
...
...
```
### 3. Push Notification Callbacks
```javascript
webengage.push.onClick(function(deeplink, customData) {
console.log("Push notification clicked");
...
});
```
## In-App Notifications
No additional changes are required to show in-app notifications.
### In-App Notification Callbacks
```javascript
webengage.notification.onShown(function(inAppData) {
console.log("In-app notification shown");
...
});
webengage.notification.onClick(function(inAppData, actionId) {
console.log("In-app notification clicked");
...
});
webengage.notification.onDismiss(function(inAppData) {
console.log("In-app notification dismissed");
...
});
```
## Troubleshooting
### 1. Manifest merger failed
```
Error: Element meta-data#com.webengage.sdk.android... at AndroidManifest.xml:... duplicated with element declared at AndroidManifest.xml:...
...
Error:
Validation failed, exiting
```
This error is caused when there are duplicate meta-data tags in your AndroidManifest.xml file. To resolve this problem, simply run the command `cordova clean`.
### 2. AAPT: Error: unbound prefix
```
A problem occurred configuring project ':app'.
> org.xml.sax.SAXParseException; systemId: file:/.../AndroidManifest.xml; lineNumber: ...; columnNumber: ...; The prefix "android" for attribute "..." associated with an element type "manifest" is not bound.
```
This error is caused when AAPT cannot identify the prefix 'android' from your AndroidManifest.xml. To resolve this error, just add the android namespace attribute to the widget tag in your `config.xml` file as shown below.
```xml
...
```
## Cordova Sample Project
Refer our [Cordova Sample Project](https://github.com/WebEngage/cordova-sample) for sample usage.