In order to integrate the Cordova Hybrid Plugin, developers need to have the AppKey and WorkspaceId generated in the previous steps. While initializing the Plugin in the app, the AppKey and WorkspaceId need to be passed.
To integrate Datagran Cordova Plugin, follow the below instructions. The latest plugin version is "1.0.3" .
**Instructions to add the Cordova hybrid plugin from Gitlab:**
1. Open the terminal and set your project path.
2. Run the below command to add the Cordova android plugin.
cordova plugin add <https://gitlab.com/datagran/datagran-cordova-plugin.git#{latest_version}>
**Instructions to update the Cordova hybrid plugin:**
1. Open the terminal and set your project path.
2. Run the below commands.
cordova plugin rm datagran-cordova-plugin
cordova plugin add <https://gitlab.com/datagran/datagran-cordova-plugin.git#{latest_version}>
Follow the below steps to setup the iOS platform.
Follow the below steps after adding the plugin.
1. Open the terminal and install cocoapods using the below command.
**sudo gem install cocoapods**
2. Set your project path on the terminal and run the below command.
**pod install**
3. Close the Xcode project and open your Project from the terminal using the below command.
**open yourproject.xcworkspace**
Add the following code in "Info.plist" file
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We need to use your location for tracking purposes</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>We need to use your location for tracking purposes</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We need to use your location for tracking purposes</string>
Add the following lines to your code to be able to initialize tracking with your own Datagran AppKey and WorkspaceId. The Cordova plugin will initialize the SDK in the app and pass the DatagranAppKey, DatagranWorkspaceId along with a couple of other parameters such as context, addGeo, DatagranBatchValue and DatagranWaitResponse. During the initialize method call, the user’s session "dg_user_id" will be automatically created inside the SDK.
document.addEventListener('deviceready', function() {
cordova.plugins.datagran.initSdk({
datagranAppKey: "5e********************19", // your Datagran Android/iOS AppKey
datagranWorkspaceId: "5e********************65", // your Datagran Android/iOS WorkspaceID
datagranBatchValue: 10,
datagranWaitResponse: 60
},
(result) => {
console.log(result);
},
(error) => {
console.error(error);
}
);
}, false);
Now the integration of the datagran Cordova plugin with the application is complete.