Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update config for data pipelines support #157

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions apps/amiapp_flutter/lib/src/customer_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,26 @@ class CustomerIOSDK extends ChangeNotifier {
} else {
logLevel = CioLogLevel.debug;
}

final InAppConfig? inAppConfig;
if (_sdkConfig?.siteId != null) {
inAppConfig = InAppConfig(siteId: _sdkConfig!.siteId);
} else {
inAppConfig = null;
}
return CustomerIO.initialize(
config: CustomerIOConfig(
siteId: _sdkConfig?.siteId ?? '',
apiKey: _sdkConfig?.apiKey ?? '',
enableInApp: true,
cdpApiKey: '${_sdkConfig?.siteId}:${_sdkConfig?.apiKey}',
migrationSiteId: _sdkConfig?.siteId,
region: Region.us,
//config options go here
trackingApiUrl: _sdkConfig?.trackingUrl ?? '',
autoTrackDeviceAttributes:
_sdkConfig?.deviceAttributesTrackingEnabled ?? true,
autoTrackPushEvents: true,
backgroundQueueMinNumberOfTasks:
_sdkConfig?.backgroundQueueMinNumOfTasks ?? 10,
backgroundQueueSecondsDelay:
_sdkConfig?.backgroundQueueSecondsDelay ?? 30.0,
logLevel: logLevel,
autoTrackDeviceAttributes:
_sdkConfig?.deviceAttributesTrackingEnabled,
apiHost: _sdkConfig?.trackingUrl,
cdnHost: _sdkConfig?.trackingUrl,
flushAt: _sdkConfig?.backgroundQueueMinNumOfTasks,
flushInterval: _sdkConfig?.backgroundQueueSecondsDelay?.toInt(),
inAppConfig: inAppConfig,
),
);
} catch (ex) {
Expand Down
53 changes: 53 additions & 0 deletions lib/config/customer_io_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import '../customer_io_enums.dart';
import '../customer_io_plugin_version.dart' as plugin_info show version;
import 'in_app_config.dart';
import 'push_config.dart';

class CustomerIOConfig {
final String source = 'Flutter';
final String version = plugin_info.version;

final String cdpApiKey;
final String? migrationSiteId;
final Region? region;
final CioLogLevel? logLevel;
final bool? autoTrackDeviceAttributes;
final String? apiHost;
final String? cdnHost;
final int? flushAt;
final int? flushInterval;
final InAppConfig? inAppConfig;
final PushConfig pushConfig;

CustomerIOConfig({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think trackApplicationLifecycleEvents is not here as its part of another ticket, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I focused mainly on Dart file changes here. native SDK implementation and testing will be handled in the other ticket you mentioned.

required this.cdpApiKey,
this.migrationSiteId,
this.region,
this.logLevel,
this.autoTrackDeviceAttributes,
this.apiHost,
this.cdnHost,
this.flushAt,
this.flushInterval,
this.inAppConfig,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking our load, if a user has provided migrationSiteId and not InAppConfig should we automatically handle it for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought the same, but doing it that way would mean losing flexibility in two scenarios:

  • Disabling in-app messaging wouldn't be possible if migrationSiteId is provided
  • If a user creates a new siteId, it could cause issues since migrationSiteId is supposed to remain the same, while in-app feature would require the new siteId

Keeping them separate gives us better control in these cases.

PushConfig? pushConfig,
}) : pushConfig = pushConfig ?? PushConfig();

Map<String, dynamic> toMap() {
return {
'cdpApiKey': cdpApiKey,
'migrationSiteId': migrationSiteId,
'region': region?.name,
'logLevel': logLevel?.name,
'autoTrackDeviceAttributes': autoTrackDeviceAttributes,
'apiHost': apiHost,
'cdnHost': cdnHost,
'flushAt': flushAt,
'flushInterval': flushInterval,
'inAppConfig': inAppConfig?.toMap(),
'pushConfig': pushConfig.toMap(),
'version': version,
'source': source
};
}
}
11 changes: 11 additions & 0 deletions lib/config/in_app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class InAppConfig {
final String siteId;

InAppConfig({required this.siteId});

Map<String, dynamic> toMap() {
return {
'siteId': siteId,
};
}
}
28 changes: 28 additions & 0 deletions lib/config/push_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'package:customer_io/customer_io_enums.dart';

class PushConfig {
PushConfigAndroid pushConfigAndroid;

PushConfig({PushConfigAndroid? android})
: pushConfigAndroid = android ?? PushConfigAndroid();

Map<String, dynamic> toMap() {
return {
'android': pushConfigAndroid.toMap(),
};
}
}

class PushConfigAndroid {
PushClickBehaviorAndroid pushClickBehavior;

PushConfigAndroid(
{this.pushClickBehavior =
PushClickBehaviorAndroid.activityPreventRestart});

Map<String, dynamic> toMap() {
return {
'pushClickBehavior': pushClickBehavior.rawValue,
};
}
}
58 changes: 3 additions & 55 deletions lib/customer_io_config.dart
Original file line number Diff line number Diff line change
@@ -1,55 +1,3 @@
import 'customer_io_enums.dart';

/// Configure plugin using CustomerIOConfig
class CustomerIOConfig {
final String siteId;
final String apiKey;
Region region;
String organizationId;
CioLogLevel logLevel;
bool autoTrackDeviceAttributes;
String trackingApiUrl;
bool autoTrackPushEvents;
int backgroundQueueMinNumberOfTasks;
double backgroundQueueSecondsDelay;
PushClickBehaviorAndroid pushClickBehaviorAndroid;

bool enableInApp;

String version;

CustomerIOConfig(
{required this.siteId,
required this.apiKey,
this.region = Region.us,
@Deprecated("organizationId is deprecated and isn't required anymore, use enableInApp instead. This field will be removed in the next release.")
this.organizationId = "",
this.logLevel = CioLogLevel.debug,
this.autoTrackDeviceAttributes = true,
this.trackingApiUrl = "",
this.autoTrackPushEvents = true,
this.backgroundQueueMinNumberOfTasks = 10,
this.backgroundQueueSecondsDelay = 30.0,
this.pushClickBehaviorAndroid = PushClickBehaviorAndroid.activityPreventRestart,
this.enableInApp = false,
this.version = ""});

Map<String, dynamic> toMap() {
return {
'siteId': siteId,
'apiKey': apiKey,
'region': region.name,
'organizationId': organizationId,
'logLevel': logLevel.name,
'autoTrackDeviceAttributes': autoTrackDeviceAttributes,
'trackingApiUrl': trackingApiUrl,
'autoTrackPushEvents': autoTrackPushEvents,
'backgroundQueueMinNumberOfTasks': backgroundQueueMinNumberOfTasks,
'backgroundQueueSecondsDelay': backgroundQueueSecondsDelay,
'pushClickBehaviorAndroid': pushClickBehaviorAndroid.rawValue,
'enableInApp': enableInApp,
'version': version,
'source': "Flutter"
};
}
}
export 'config/customer_io_config.dart';
export 'config/in_app_config.dart';
export 'config/push_config.dart';
5 changes: 0 additions & 5 deletions lib/customer_io_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'customer_io_config.dart';
import 'customer_io_const.dart';
import 'customer_io_inapp.dart';
import 'customer_io_platform_interface.dart';
import 'customer_io_plugin_version.dart';

/// An implementation of [CustomerIOPlatform] that uses method channels.
class CustomerIOMethodChannel extends CustomerIOPlatform {
Expand Down Expand Up @@ -66,10 +65,6 @@ class CustomerIOMethodChannel extends CustomerIOPlatform {
required CustomerIOConfig config,
}) async {
try {
config.version = version;
if (!config.enableInApp && config.organizationId.isNotEmpty) {
config.enableInApp = true;
}
await methodChannel.invokeMethod(MethodConsts.initialize, config.toMap());
} on PlatformException catch (exception) {
handleException(exception);
Expand Down
Loading
Loading