Skip to content

Commit

Permalink
feature: added offline storage functionality for cordova
Browse files Browse the repository at this point in the history
  • Loading branch information
ndesai-newrelic committed Mar 5, 2024
1 parent d98ee2d commit bceac70
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 11 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

# 6.2.6

### New in this release
In this release, we are introducing several new features and updates:

* Added Offline Harvesting Feature: This new feature enables the preservation of harvest data that would otherwise be lost when the application lacks an internet connection. The stored harvests will be sent once the internet connection is re-established and the next harvest upload is successful.
* Introduced setMaxOfflineStorageSize API: This new API allows the user to determine the maximum volume of data that can be stored locally. This aids in better management and control of local data storage.
* Updated native iOS Agent: We've upgraded the native iOS agent to version 7.4.9, which includes performance improvements and bug fixes.
* Updated native Android Agent: We've also upgraded the native Android agent to version 7.3.0 bringing benefits like improved stability and enhanced features.

These enhancements help to improve overall user experience and application performance.

# 6.2.5

### New in this release
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Currently, the plugin supports the following agent configuration options:
* Possible values are `true` and `false`. Defaults to `false`.
* `CONSOLE_LOGS_ENABLED`: Enable or disable reporting javascript console logs as custom events.
* Possible values are `true` and `false`. Defaults to `false`.
* `OFFLINE_STORAGE_ENABLED`: Enable or disable offline data storage when no internet connection is available. .
* Possible values are `true` and `false`. Defaults to `true`.
# Updating the plugin
Update the New Relic Cordova plugin to the latest released version easily via the following command:
```
Expand Down Expand Up @@ -211,6 +213,12 @@ Our plugin uses the same APIs as our native agents. See the examples below for u
NewRelic.setMaxEventPoolSize(2000);
```
### [setMaxOfflineStorageSize](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/set-max-offline-storage)(megaBytes: number): void;
> Sets the maximum size of total data that can be stored for offline storage.By default, mobile monitoring can collect a maximum of 100 megaBytes of offline storage. When a data payload fails to send because the device doesn't have an internet connection, it can be stored in the file system until an internet connection has been made. After a typical harvest payload has been successfully sent, all offline data is sent to New Relic and cleared from storage.
```js
NewRelic.setMaxOfflineStorageSize(200);
```
### The following methods allow you to set some agent configurations *after* the agent has started:
By default, these configurations are already set to true on agent start.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newrelic-cordova-plugin",
"version": "6.2.5",
"version": "6.2.6",
"description": "New Relic Cordova Plugin for iOS and Android",
"repo": "https://github.com/newrelic/newrelic-cordova-plugin/",
"scripts": {
Expand Down
11 changes: 7 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="newrelic-cordova-plugin" version="6.2.5">
id="newrelic-cordova-plugin" version="6.2.6">
<name>NewRelic</name>
<description>New Relic Cordova Plugin for iOS and Android</description>
<author>New Relic</author>
Expand All @@ -18,7 +18,7 @@
<engine name="cordova-android" version=">=5.0.0" />
</engines>

<preference name="PLUGIN_VERSION" default="6.2.5" />
<preference name="PLUGIN_VERSION" default="6.2.6" />
<preference name="CRASH_REPORTING_ENABLED" default="true" />
<preference name="DISTRIBUTED_TRACING_ENABLED" default="true" />
<preference name="INTERACTION_TRACING_ENABLED" default="true" />
Expand All @@ -29,6 +29,7 @@
<preference name="COLLECTOR_ADDRESS" default="x" />
<preference name="CRASH_COLLECTOR_ADDRESS" default="x" />
<preference name="FEDRAMP_ENABLED" default="false" />
<preference name="OFFLINE_STORAGE_ENABLED" default="true" />
<preference name="CONSOLE_LOGS_ENABLED" default="true" />


Expand All @@ -53,6 +54,7 @@
<preference name="COLLECTOR_ADDRESS" value="$COLLECTOR_ADDRESS" />
<preference name="CRASH_COLLECTOR_ADDRESS" value="$CRASH_COLLECTOR_ADDRESS" />
<preference name="FEDRAMP_ENABLED" value="$FEDRAMP_ENABLED" />
<preference name="OFFLINE_STORAGE_ENABLED" value="$OFFLINE_STORAGE_ENABLED" />
<preference name="CONSOLE_LOGS_ENABLED" value="$CONSOLE_LOGS_ENABLED" />
<param name="ios-package" value="NewRelicCordovaPlugin" onload="true" />
</feature>
Expand All @@ -71,7 +73,7 @@
<source url="https://cdn.cocoapods.org/" />
</config>
<pods use-frameworks="true">
<pod name="NewRelicAgent" spec="7.4.8" />
<pod name="NewRelicAgent" spec="7.4.9" />
</pods>
</podspec>

Expand All @@ -81,7 +83,7 @@

<platform name="android">
<preference name="ANDROID_APP_TOKEN" default="x" />
<preference name="ANDROID_AGENT_VER" default="7.2.0" />
<preference name="ANDROID_AGENT_VER" default="7.3.0" />

<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
Expand Down Expand Up @@ -109,6 +111,7 @@
<preference name="COLLECTOR_ADDRESS" value="$COLLECTOR_ADDRESS" />
<preference name="CRASH_COLLECTOR_ADDRESS" value="$CRASH_COLLECTOR_ADDRESS" />
<preference name="FEDRAMP_ENABLED" value="$FEDRAMP_ENABLED" />
<preference name="OFFLINE_STORAGE_ENABLED" value="$OFFLINE_STORAGE_ENABLED" />
<preference name="CONSOLE_LOGS_ENABLED" value="$CONSOLE_LOGS_ENABLED" />
</config-file>

Expand Down
8 changes: 8 additions & 0 deletions src/android/NewRelicCordovaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
}
if (preferences.getString("default_interactions_enabled", "true").equalsIgnoreCase("false")) {
NewRelic.disableFeature(FeatureFlag.DefaultInteractions);
}
if (preferences.getString("offline_storage_enabled", "true").equalsIgnoreCase("true")) {
NewRelic.enableFeature(FeatureFlag.OfflineStorage);
}
if (preferences.getString("fedramp_enabled", "false").equalsIgnoreCase("true")) {
NewRelic.enableFeature(FeatureFlag.FedRampEnabled);
Expand Down Expand Up @@ -403,6 +406,11 @@ public void run() {
NewRelic.setMaxEventBufferTime(maxEventBufferTimeInSeconds);
break;
}
case "setMaxOfflineStorageSize": {
final int megabytes = args.getInt(0);
NewRelic.setMaxOfflineStorageSize(megabytes);
break;
}
case "setMaxEventPoolSize": {
final int maxPoolSize = args.getInt(0);
NewRelic.setMaxEventPoolSize(maxPoolSize);
Expand Down
2 changes: 2 additions & 0 deletions src/ios/NewRelicCordovaPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@

- (void)setMaxEventPoolSize:(CDVInvokedUrlCommand *)command;

- (void)setMaxOfflineStorageSize:(CDVInvokedUrlCommand *)command;

- (void)analyticsEventEnabled:(CDVInvokedUrlCommand *) command;

- (void)networkRequestEnabled:(CDVInvokedUrlCommand *) command;
Expand Down
9 changes: 9 additions & 0 deletions src/ios/NewRelicCordovaPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ - (void)pluginInitialize
if (![self shouldDisableFeature:config[@"fedramp_enabled"]]) {
[NewRelic enableFeatures:NRFeatureFlag_FedRampEnabled];
}
if (![self shouldDisableFeature:config[@"offline_storage_enabled"]]) {
[NewRelic enableFeatures:NRFeatureFlag_OfflineStorage];
}

// Set log level depending on loggingEnabled and logLevel
NRLogLevels logLevel = NRLogLevelWarning;
Expand Down Expand Up @@ -356,6 +359,12 @@ - (void)setMaxEventPoolSize:(CDVInvokedUrlCommand *)command {
[NewRelic setMaxEventPoolSize:uint_maxPoolSize];
}

- (void)setMaxOfflineStorageSize:(CDVInvokedUrlCommand *)command {
NSNumber* megaBytes = [command.arguments objectAtIndex:0];
unsigned int uint_megaBytes = megaBytes.unsignedIntValue;
[NewRelic setMaxOfflineStorageSize:uint_megaBytes];
}

- (void)analyticsEventEnabled:(CDVInvokedUrlCommand *)command {
// This should only be an android method call, so we do nothing here.
return;
Expand Down
20 changes: 14 additions & 6 deletions www/js/newrelic.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "setMaxEventPoolSize", [maxPoolSize]);
},

/**
* Sets the maximum size of total data that can be stored for offline storage..
* @param {number} maxPoolSize The Maximum size in megaBytes that can be stored in the file system.
*/
setMaxOfflineStorageSize: function (megaBytes, cb, fail) {
cordova.exec(cb, fail, "NewRelicCordovaPlugin", "setMaxOfflineStorageSize", [megaBytes]);
},

/**
* FOR ANDROID ONLY.
* Enable or disable collection of event data.
Expand Down Expand Up @@ -490,14 +498,14 @@
_arguments[1] = options;
}

if(options && 'body' in options) {
networkRequest.bytesSent = options.body.length;
if (options && 'body' in options && options.body !== undefined) {
networkRequest.bytesSent = options.body.length;
} else {
networkRequest.bytesSent = 0;
networkRequest.bytesSent = 0;
}
if (networkRequest.method === undefined || networkRequest.method === "" ) {
networkRequest.method = 'GET';

if (networkRequest.method === undefined || networkRequest.method === "") {
networkRequest.method = 'GET';
}
return new Promise(function (resolve, reject) {
// pass through to native fetch
Expand Down

0 comments on commit bceac70

Please sign in to comment.