Installing and Configuring the eG Mobile Agent for Cordova Applications
Cordova most commonly refers to Apache Cordova, a free software framework that lets people build mobile apps using web tools like HTML, CSS, and JavaScript. Instead of using platform-specific languages like Java for Android or Swift for iOS, developers write one codebase that runs inside a native device wrapper (WebView) and connects to phone hardware through plugins.
To measure the quality of interactions between users and a Cordova application, you first need to install and configure a specialized eG mobile agent plugin on the target application host. The procedure for deploying this plugin varies according to the platform/phone type - i.e., whether Android or iOS. The sections below discuss the platform-specific procedures.
Installing and Configuring the eG Mobile Agent for a Cordova Application on Android
For this, follow the steps below:
-
Login to the application host.
-
Then, open the browser, connect to the eG management console, and then login to the eG administrative interface.
-
Follow the Infrastructure -> Add /Modify menu sequence. Figure 1 will appear. In Figure 1, pick Mobile RUM as the Component type, and click the Add New Component button to add a new Mobile RUM component.
-
Figure 2 will then appear. Provide a Nick name for the Cordova application you want to monitor.
Figure 2 : Adding the target Cordova application as a Mobile RUM component
-
Then, select the Mobile RUM collector to which the eG Mobile Agent should send the performance metrics it gathers from the target application.
-
Next, assign a Remote agent to the Mobile RUM component. This is the agent that will pull metrics from the Mobile RUM collector and reports the same to the eG manager.
-
To install the eG mobile agent on Cordova, set Application type as Hybrid.
-
Finally, click the Add button.
-
Figure 3 will then appear. Proceed to download the eG mobile agent from the manager. For that, in the right panel of Figure 3, first click on the Cordova button. Then, click on the Download button against Download eG Agent for Cordova.
- The eG Mobile agent will be downloaded as a zipped file. Now, extract the contents of the zip to the download location.
-
Then, click on the Copy to Clipboard link above the code snippet displayed against 'Include this line...', as indicated by Figure 4.
Figure 4 : Copying code snippet for instrumenting Cordova application
-
Next, in an Editor, open the index.html file located in the in the /www folder at the root level of your project directory. This main file is an HTML5 file that contains the application skeleton. This file loads all the web resources (scripts and stylesheets). To make sure that the application loads the eG RUM script, edit this file and insert the code snippet you copied to clipboard (at step 11 above) into the header section.
-
Then, save the file.
-
Now, revisit Figure 4 in the eG management console. Go back to the code snippet displayed against 'Include this line....', and copy the value displayed against 'Site_Name' and 'beacon-URL' in the snippet.
-
Next, go to the command prompt, switch to the application's root directory, and issue the following command to add the eG mobile agent plugin to the target Cordova application:
cordova plugin add <PATH>/eginnovations-cordova-plugin --variable ANDROID_APP_TOKEN="<Site_Name_In_Snippet>" --variable MANAGER_URL="<Beacon-URL_in_Snippet>" --variable LOG_LEVEL="6"
When issuing the command, make sure that you replace the variables highlighted in Bold in the command with the appropriate values you copied from the snippet in Figure 4. Likewise, make sure you replace the <PATH> with the download path of the eG mobile agent.
-
Next, proceed to edit the MainApplication.java file (in the [YourProjectFolder]/android/app/src/main/java/[your]/[package]/[name]/ directory), and include the following 'import' statements in the file. These statements instruct the compiler to load the eG mobile agent and all its dependent classes and packages.
Copyimport com.eg.agent.android.eGAndroidAgent;
import com.eg.agent.android.AppPlatform; -
Next, inside the onCreate method, initialize the eG mobile agent by inserting the following code:
eGAndroidAgent.withCollectorHost("<APP_TOKEN>","<URL>").start(getApplicationContext()); eGAndroidAgent.setAppliactionPlatform(AppPlatform.Cordova);
After inserting, make sure you replace the variables highlighted in Bold in the code above with the following values:
-
<APP_TOKEN>: Replace this with the value displayed against 'Site_Name' in the code snippet of Figure 4.
-
<URL>: Replace this with the value displayed against 'beacon-URL' in the code snippet of Figure 4.
-
-
Finally, save the file.
-
Now, proceed to edit the gradle.properties file (in the Android project's root directory), and add the eG mobile agent to the 'ignorelist' of the file, as shown below:
Copyandroid.jetifier.ignorelist=rewriter-agent-x.x.x.jarThis instructs the Android Gradle Plugin (AGP) to skip the automatic Jetifier migration process for eG mobile agent libraries. Its because this process may sometimes spew errors and cause application crashes.
-
Then, save the gradle.properties file.
-
Then, edit the AndroidManifest.xml file in the root of the project source set.
-
Ensure that `android:usesCleartextTraffic="true"` is added in the <application> tag, as shown by the entry highlighted in Bold below:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
This allows the application to transmit over unencrypted HTTP connections
-
Clean and build the project in Android Studio. Run it on a simulator or mobile device.
-
Finally, login to eG manager application to start seeing data.
Installing and Configuring the eG Mobile Agent for a Cordova Application on iOS
-
Login to the application host.
-
Then, open the browser, connect to the eG management console, and then login to the eG administrative interface.
-
Follow the Infrastructure -> Add /Modify menu sequence. Figure 5 will appear. In Figure 5, pick Mobile RUM as the Component type, and click the Add New Component button to add a new Mobile RUM component.
-
Figure 6 will then appear. Provide a Nick name for the Cordova application you want to monitor.
Figure 6 : Adding the target Cordova application as a Mobile RUM component
-
Then, select the Mobile RUM collector to which the eG Mobile Agent should send the performance metrics it gathers from the target application.
-
Next, assign a Remote agent to the Mobile RUM component. This is the agent that will pull metrics from the Mobile RUM collector and reports the same to the eG manager.
-
To install the eG mobile agent on Cordova, set Application type as Hybrid.
-
Finally, click the Add button.
-
Figure 7 will then appear. Proceed to download the eG mobile agent from the manager. For that, in the right panel of Figure 7, first click on the Cordova button. Then, click on the Download button against Download eG Agent for Cordova.
- The eG Mobile agent will be downloaded as a zipped file. Extract the contents of the zip to the download location.
-
Then, click on the Copy to Clipboard link above the code snippet displayed against 'Include this line...', as indicated by Figure 8.
Figure 8 : Copying code snippet for instrumenting Cordova application
-
Next, in an Editor, open the index.html file located in the in the /www folder at the root level of your project directory. This main file is an HTML5 file that contains the application skeleton. This file loads all the web resources (scripts and stylesheets). To make sure that the application loads the eG RUM script, edit this file and insert the code snippet you copied to clipboard (at step 11 above) into the header section.
-
Then, save the file.
-
Now, revisit Figure 8 in the eG management console. Go back to the code snippet displayed against 'Include this line....', and copy the value displayed against 'Site_Name' and 'beacon-URL' in the snippet.
-
Next, go to the command prompt, switch to the application's root directory, and issue the following command to add the eG mobile agent plugin to the target Cordova application:
cordova plugin add <PATH>/eginnovations-cordova-plugin --variable ANDROID_APP_TOKEN="<Site_Name_In_Snippet>" --variable MANAGER_URL="<Beacon-URL_in_Snippet>" --variable LOG_LEVEL="6"
When issuing the command, make sure that you replace the variables highlighted in Bold in the command with the appropriate values you copied from the snippet in Figure 8. Likewise, make sure you replace the <PATH> with the download path of the eG mobile agent.
-
Next, you need to copy the eG mobile agent libraries directly into your application bundle and sign it using your project's code-signing certificate. This setting is mandatory for Xcode to distribute the target application, as it now contains a third-party dynamic framework (eG mobile agent ) and its libraries. This setting ensures that the application code continues to comply with Apple's security requirements and prevents immediate runtime crashes upon launch.
For this, do the following:
-
Click your project at the top of the left Xcode navigator panel.
-
Select your main application Target from the target list and open the General tab at the top.
-
Next, scroll down to the Frameworks, Libraries, and Embedded Content section in the General settings of your project.
-
Locate the eGMobileAPM.xcframework library here.
-
Then, click the drop-down menu in the Embed column next to the library name, and select Embed & Sign (see Figure 9)
.Figure 9 : Setting the Embed and Sign option for the eG mobile agent library
-
-
Clean and build the project in Android Studio. Run it on a simulator or mobile device.
-
Finally, login to eG manager application to start seeing data.
Troubleshooting
Troubleshooting the Collector Reachability Issue
The eG manager might be running with self - signed SSL certificates in some deployments. A recent enforcement for Android 7 and above blocks outbound connections from mobile applications on Android to 3rd party self-signed applications / services. This means that, if a mobile application that is running on Android 7 (or above) is being monitored as a Mobile RUM component, then the eG mobile agent installed on such an application will not be able to reach the RUM collector on the eG manager. To allow this communication therefore, do the following:
-
Create a network_security_config.xml file in the \platforms\android\app\src\main\res\xml\ directory.
-
In the file, include the following lines of code:
<network-security-config>
<base-config cleartextTrafficPermitted="true"> <trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
-
Save the file.
Troubleshooting JS Errors in Ionic Angular Applications
To resolve such issues, do the following:
-
Edit the app,module.ts file in the [Project-Root]/src/app/ directory.
-
Append the following lines of code in the file.
import { ErrorHandler } from '@angular/core'; declare var EGRUM: any;
@Injectable()
export class EGRUMErrorHandler implements ErrorHandler { handleError(err: any): void {
EGRUM.onerror({ message: err.message,
filename: err.filename, lineNumber: err.lineNumber, columnNumber: err.columnNumber, stack: err.stack,
meta: { type: "Internal Error." }
});
}
}
@NgModule({
declarations: [AppComponent], entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule], providers: [
{provide: ErrorHandler, useClass: EGRUMErrorHandler}
],
bootstrap: [AppComponent]
})
-
Finally, save the file.