Skip to content

Commit

Permalink
feat: added support for configuring gzip compression of the payload t…
Browse files Browse the repository at this point in the history
…o data plane
  • Loading branch information
Desu Sai Venkat committed Dec 14, 2023
1 parent da05e84 commit 31823a2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions packages/plugins/rudder_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ check [the documentation page](https://docs.rudderstack.com/rudderstack-sdk-inte
- Data Residency, Custom Context from version `2.4.0`
- Configurable Collection of Device Id from version `2.5.0`
- Database Encryption as a separate plugin from version `2.6.0`
- Gzip compression of payload from version `2.8.0`

## Contact Us

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static RudderConfig getRudderConfigObject(Map<String, Object> configMap,
.withAutoCollectAdvertId((Boolean) configMap.get("autoCollectAdvertId"))
.withCollectDeviceId((Boolean) configMap.get("collectDeviceId"))
.withControlPlaneUrl((String) configMap.get("controlPlaneUrl"))
.withGzip((Boolean) configMap.get("gzip"))
// disabling the below three flags on the native side as they are handled on the flutter side
.withTrackLifecycleEvents(false)
.withRecordScreenViews(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Constants {
// default duration for inactivity is 30 minutes or 1800000 milliseconds for Web Platforms
static const int DEFAULT_SESSION_TIMEOUT_WEB = 1800000;

// default value for whether to gzip compress the request payload or not
static const bool DEFAULT_GZIP_COMPRESSION = true;

// default timeout for event flush
// if events are registered and flushQueueSize is not reached
// events will be flushed to server after sleepTimeOut seconds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class RudderConfig {
_mobileConfigMap['sessionTimeoutInMillis'] =
mobileConfig.sessionTimeoutInMillis;
}
_mobileConfigMap['gzip'] = mobileConfig.gzip;
}
if (Utils.isEmpty(controlPlaneUrl)) {
RudderLogger.logError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class MobileConfig {
/// @param sessionTimeoutInMillis (duration of inactivity of session in milliseconds)
final int _sessionTimeoutInMillis;

/// @param gzip whether to gzip compress the request payload or not
final bool _gzip;

MobileConfig(
{dbCountThreshold = Constants.DB_COUNT_THRESHOLD,
autoCollectAdvertId = Constants.AUTO_COLLECT_ADVERT_ID,
Expand All @@ -42,7 +45,8 @@ class MobileConfig {
configRefreshInterval = Constants.CONFIG_REFRESH_INTERVAL,
DBEncryptionInterface? dbEncryption,
autoSessionTracking = Constants.AUTO_SESSION_TRACKING,
sessionTimeoutInMillis = Constants.DEFAULT_SESSION_TIMEOUT_MOBILE})
sessionTimeoutInMillis = Constants.DEFAULT_SESSION_TIMEOUT_MOBILE,
gzip = Constants.DEFAULT_GZIP_COMPRESSION})
: _dbCountThreshold = dbCountThreshold,
_autoCollectAdvertId = autoCollectAdvertId,
_collectDeviceId = collectDeviceId,
Expand All @@ -52,7 +56,8 @@ class MobileConfig {
_configRefreshInterval = configRefreshInterval,
_dbEncryption = dbEncryption,
_autoSessionTracking = autoSessionTracking,
_sessionTimeoutInMillis = sessionTimeoutInMillis;
_sessionTimeoutInMillis = sessionTimeoutInMillis,
_gzip = gzip;

int get dbCountThreshold => _dbCountThreshold;

Expand All @@ -73,4 +78,6 @@ class MobileConfig {
bool get autoSessionTracking => _autoSessionTracking;

int get sessionTimeoutInMillis => _sessionTimeoutInMillis;

bool get gzip => _gzip;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString* userId = [call.arguments objectForKey:@"userId"];
NSDictionary* traits = nil;
RSOption* options = nil;

if ([call.arguments objectForKey:@"traits"]) {
traits = [[self getRudderTraitsObject:[call.arguments objectForKey:@"traits"]] dict];
}

if ([call.arguments objectForKey:@"options"]) {
options = [self getRudderOptionsObject:[call.arguments objectForKey:@"options"]];
}

[[RSClient sharedInstance] identify:userId traits:traits options:options];
return;
} else if ([call.method isEqualToString:@"track"]) {
NSString* eventName = [call.arguments objectForKey:@"eventName"];
NSDictionary* eventProperties = nil;
RSOption* options = nil;

if ([call.arguments objectForKey:@"properties"]) {
eventProperties = [call.arguments objectForKey:@"properties"];
}
Expand All @@ -85,12 +85,12 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
}
[[RSClient sharedInstance] track:eventName properties:eventProperties options:options];
return;

} else if ([call.method isEqualToString:@"screen"]) {
NSString* screenName = [call.arguments objectForKey:@"screenName"];
NSMutableDictionary* screenProperties = nil;
RSOption* options = nil;

if ([call.arguments objectForKey:@"properties"]) {
screenProperties = [call.arguments objectForKey:@"properties"];
}
Expand All @@ -109,7 +109,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString* groupId = [call.arguments objectForKey:@"groupId"];
NSDictionary<NSString*, NSObject*>* groupTraits = nil;
RSOption* options = nil;

if ([call.arguments objectForKey:@"groupTraits"]) {
groupTraits =
[[self getRudderTraitsObject:[call.arguments objectForKey:@"groupTraits"]] dict];
Expand All @@ -121,7 +121,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
return;
} else if ([call.method isEqualToString:@"alias"]) {
RSOption* options = nil;

if ([call.arguments objectForKey:@"options"]) {
options = [self getRudderOptionsObject:[call.arguments objectForKey:@"options"]];
}
Expand Down Expand Up @@ -211,6 +211,7 @@ - (RSConfig*)getRudderConfigObject:(NSDictionary*)configDict {
[configBuilder
withConfigRefreshInteval:[[configDict objectForKey:@"configRefreshInterval"] intValue]];
[configBuilder withCollectDeviceId:[[configDict objectForKey:@"collectDeviceId"] boolValue]];
[configBuilder withGzip: [[configDict objectForKey:@"gzip"] boolValue]];
[configBuilder
withTrackLifecycleEvens:[[configDict objectForKey:@"trackLifecycleEvents"] boolValue]];
[configBuilder withRecordScreenViews:[[configDict objectForKey:@"recordScreenViews"] boolValue]];
Expand All @@ -221,11 +222,11 @@ - (RSConfig*)getRudderConfigObject:(NSDictionary*)configDict {
if ([dataResidencyServer isEqualToString:@"EU"]) {
[configBuilder withDataResidencyServer:EU];
}

if(_dbEncryption != nil) {
[configBuilder withDBEncryption: _dbEncryption];
}

if (integrationList != nil) {
for (id<RSIntegrationFactory> integration in integrationList) {
[configBuilder withFactory:integration];
Expand Down

0 comments on commit 31823a2

Please sign in to comment.