Skip to content

Commit

Permalink
feat: added support for different session configuration between mobil…
Browse files Browse the repository at this point in the history
…e and web platforms
  • Loading branch information
Desu Sai Venkat committed Nov 22, 2023
1 parent 9844c37 commit ede1ff3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ class Constants {
// default threshold of number of events to be persisted in sqlite db
static const int DB_COUNT_THRESHOLD = 10000;

// default value for automatic tracking of user sessions
static const bool AUTO_SESSION_TRACKING = true;

// default duration for inactivity is 5 minutes or 300000 milliseconds for Mobile Platforms
static const int DEFAULT_SESSION_TIMEOUT_MOBILE = 300000;

// default duration for inactivity is 10 minutes or 600000 milliseconds for Web Platforms
static const int DEFAULT_SESSION_TIMEOUT_WEB = 600000;

// 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 @@ -31,7 +31,6 @@ class RudderConfig {
String dataPlaneUrl, // used in android/ios/web
int flushQueueSize, // all
int logLevel, //all
bool autoSessionTracking, // all
MobileConfig? mobileConfig,
WebConfig? webConfig,
String controlPlaneUrl, //all
Expand All @@ -44,6 +43,7 @@ class RudderConfig {
final Map<String, String> queueOpts = {};
final Map<String, String> beaconOpts = {};
final Map<String, dynamic> cookieConsent = {};
final Map<String, dynamic> sessionOpts = {};

if (Utils.isEmpty(dataPlaneUrl)) {
RudderLogger.logError(
Expand Down Expand Up @@ -76,9 +76,6 @@ class RudderConfig {
? "INFO"
: "DEBUG";

_mobileConfigMap['autoSessionTracking'] = autoSessionTracking;
_webConfigMap['autoSessionTracking'] = autoSessionTracking;

if (mobileConfig != null) {
if (mobileConfig.dbCountThreshold < 0) {
RudderLogger.logError("invalid dbCountThreshold. Set to default");
Expand Down Expand Up @@ -112,6 +109,16 @@ class RudderConfig {
_mobileConfigMap['trackLifecycleEvents'] =
mobileConfig.trackLifecycleEvents;
_mobileConfigMap['recordScreenViews'] = mobileConfig.recordScreenViews;
_mobileConfigMap['autoSessionTracking'] =
mobileConfig.autoSessionTracking;
if (mobileConfig.sessionTimeoutInMillis < 0) {
RudderLogger.logError("invalid sessionTimeoutInMillis. Set to default");
_mobileConfigMap['sessionTimeoutInMillis'] =
Constants.DEFAULT_SESSION_TIMEOUT_MOBILE;
} else {
_mobileConfigMap['sessionTimeoutInMillis'] =
mobileConfig.sessionTimeoutInMillis;
}
}
if (Utils.isEmpty(controlPlaneUrl)) {
RudderLogger.logError(
Expand Down Expand Up @@ -181,6 +188,14 @@ class RudderConfig {
_webConfigMap["destSDKBaseUrl"] =
Constants.DEFAULT_DESTINATION_SDK_BASE_URL;
}
sessionOpts['autoTrack'] = webConfig.autoSessionTracking;
if (webConfig.sessionTimeoutInMillis < 0) {
RudderLogger.logError("invalid sessionTimeoutInMillis. Set to default");
sessionOpts['timeout'] = Constants.DEFAULT_SESSION_TIMEOUT_WEB;
} else {
sessionOpts['timeout'] = webConfig.sessionTimeoutInMillis;
}
_webConfigMap["sessions"] = sessionOpts;
}
}

Expand Down Expand Up @@ -249,15 +264,6 @@ class RudderConfigBuilder {
return this;
}

bool __autoSessionTracking = Constants.AUTO_SESSION_TRACKING;

/// @param autoSessionTracking Set it true to enable auto session tracking
/// @return RudderConfigBuilder
RudderConfigBuilder withAutoSessionTracking(bool autoSessionTracking) {
__autoSessionTracking = autoSessionTracking;
return this;
}

MobileConfig __mobileConfig = MobileConfig();

RudderConfigBuilder withMobileConfig(MobileConfig mobileConfig) {
Expand Down Expand Up @@ -314,7 +320,6 @@ class RudderConfigBuilder {
__dataPlaneUrl,
__flushQueueSize,
__isDebug ? RudderLogger.DEBUG : __logLevel,
__autoSessionTracking,
__mobileConfig,
__webConfig,
__controlPlaneUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,33 @@ class MobileConfig {
/// @param dbEncryption whether the SDK should encrypt the DB
final DBEncryptionInterface? _dbEncryption;

/// @param autoSessionTracking Whether to track session automatically
final bool _autoSessionTracking;

/// @param sessionTimeoutInMillis (duration of inactivity of session in milliseconds)
final int _sessionTimeoutInMillis;

MobileConfig(
{dbCountThreshold = Constants.DB_COUNT_THRESHOLD,
autoCollectAdvertId = Constants.AUTO_COLLECT_ADVERT_ID,
collectDeviceId = Constants.COLLECT_DEVICE_ID,
trackLifecycleEvents = Constants.TRACK_LIFECYCLE_EVENTS,
recordScreenViews = Constants.RECORD_SCREEN_VIEWS,
int sleepTimeOut = Constants.SLEEP_TIMEOUT,
int configRefreshInterval = Constants.CONFIG_REFRESH_INTERVAL,
DBEncryptionInterface? dbEncryption})
sleepTimeOut = Constants.SLEEP_TIMEOUT,
configRefreshInterval = Constants.CONFIG_REFRESH_INTERVAL,
DBEncryptionInterface? dbEncryption,
autoSessionTracking = Constants.AUTO_SESSION_TRACKING,
sessionTimeoutInMillis = Constants.DEFAULT_SESSION_TIMEOUT_WEB})
: _dbCountThreshold = dbCountThreshold,
_autoCollectAdvertId = autoCollectAdvertId,
_collectDeviceId = collectDeviceId,
_trackLifecycleEvents = trackLifecycleEvents,
_recordScreenViews = recordScreenViews,
_sleepTimeOut = sleepTimeOut,
_configRefreshInterval = configRefreshInterval,
_dbEncryption = dbEncryption;
_dbEncryption = dbEncryption,
_autoSessionTracking = autoSessionTracking,
_sessionTimeoutInMillis = sessionTimeoutInMillis;

int get dbCountThreshold => _dbCountThreshold;

Expand All @@ -59,4 +69,8 @@ class MobileConfig {
int get configRefreshInterval => _configRefreshInterval;

DBEncryptionInterface? get dbEncryption => _dbEncryption;

bool get autoSessionTracking => _autoSessionTracking;

int get sessionTimeoutInMillis => _sessionTimeoutInMillis;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class WebConfig {
///cookie consent managers, e.g ("oneTrust", true), default empty
final Map<String, bool>? _cookieConsentManagers;

/// @param autoSessionTracking whether to track session automatically
final bool _autoSessionTracking;

/// @param sessionTimeoutInMillis (duration of inactivity of session in milliseconds)
final int _sessionTimeoutInMillis;

WebConfig(
{loadIntegration = Constants.DEFAULT_LOAD_INTEGRATION,
secureCookie = Constants.DEFAULT_SECURE_COOKIE,
Expand All @@ -50,6 +56,8 @@ class WebConfig {
int beaconFlushQueueInterval =
Constants.DEFAULT_BEACON_FLUSH_QUEUE_INTERVAL,
destSDKBaseURL = Constants.DEFAULT_DESTINATION_SDK_BASE_URL,
autoSessionTracking = Constants.AUTO_SESSION_TRACKING,
sessionTimeoutInMillis = Constants.DEFAULT_SESSION_TIMEOUT_WEB,
Map<String, bool>? cookieConsentManagers})
: _loadIntegration = loadIntegration,
_secureCookie = secureCookie,
Expand All @@ -62,6 +70,8 @@ class WebConfig {
_maxBeaconItems = maxBeaconItems,
_beaconFlushQueueInterval = beaconFlushQueueInterval,
_destSDKBaseURL = destSDKBaseURL,
_autoSessionTracking = autoSessionTracking,
_sessionTimeoutInMillis = sessionTimeoutInMillis,
_cookieConsentManagers = cookieConsentManagers;

String get destSDKBaseURL => _destSDKBaseURL;
Expand All @@ -87,4 +97,8 @@ class WebConfig {
int get minRetryDelay => _minRetryDelay;

int get maxRetryDelay => _maxRetryDelay;

bool get autoSessionTracking => _autoSessionTracking;

int get sessionTimeoutInMillis => _sessionTimeoutInMillis;
}

0 comments on commit ede1ff3

Please sign in to comment.