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

add Builder to AdjustConfig,AdjustEvent and AdjustThirdPartySharing on top of current functionality #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 19 additions & 33 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:adjust_sdk/adjust_event_failure.dart';
import 'package:adjust_sdk/adjust_event_success.dart';
import 'package:adjust_sdk/adjust_session_failure.dart';
import 'package:adjust_sdk/adjust_session_success.dart';
import 'package:adjust_sdk/adjust_extensions.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -93,17 +94,13 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
// Platform messages are asynchronous, so we initialize in an async method.
initPlatformState() async {
AdjustConfig config =
new AdjustConfig('2fm9gkqubvpc', AdjustEnvironment.sandbox);
config.logLevel = AdjustLogLevel.verbose;

config.setUrlStrategy(['adjust.net.in', 'adjust.com'], true, false);
//config.setUrlStrategy(['adjust.world', 'adjust.com'], true, false);
//config.setUrlStrategy(['adjust.cn'], true, false);
//config.setUrlStrategy(['eu.adjust.com'], true, true);
//config.setUrlStrategy(['us.adjust.com'], true, true);
//config.setUrlStrategy(['tr.adjust.com'], true, true);

config.attributionCallback = (AdjustAttribution attributionChangedData) {
AdjustConfigBuilder.create('2fm9gkqubvpc', AdjustEnvironment.sandbox)
.setLogLevel(AdjustLogLevel.verbose)
.withUrlStrategy([
'adjust.net.in',
'adjust.com'
], true, false).setAttributionCallback(
(AdjustAttribution attributionChangedData) {
print('[Adjust]: Attribution changed!');

if (attributionChangedData.trackerToken != null) {
Expand Down Expand Up @@ -139,9 +136,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
print(
'[Adjust]: Cost currency: ' + attributionChangedData.costCurrency!);
}
};

config.sessionSuccessCallback = (AdjustSessionSuccess sessionSuccessData) {
}).setSessionSuccessCallback((AdjustSessionSuccess sessionSuccessData) {
print('[Adjust]: Session tracking success!');

if (sessionSuccessData.message != null) {
Expand All @@ -156,9 +151,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (sessionSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionSuccessData.jsonResponse!);
}
};

config.sessionFailureCallback = (AdjustSessionFailure sessionFailureData) {
}).setSessionFailureCallback((AdjustSessionFailure sessionFailureData) {
print('[Adjust]: Session tracking failure!');

if (sessionFailureData.message != null) {
Expand All @@ -177,9 +170,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (sessionFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + sessionFailureData.jsonResponse!);
}
};

config.eventSuccessCallback = (AdjustEventSuccess eventSuccessData) {
}).setEventSuccessCallback((AdjustEventSuccess eventSuccessData) {
print('[Adjust]: Event tracking success!');

if (eventSuccessData.eventToken != null) {
Expand All @@ -200,9 +191,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (eventSuccessData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventSuccessData.jsonResponse!);
}
};

config.eventFailureCallback = (AdjustEventFailure eventFailureData) {
}).setEventFailureCallback((AdjustEventFailure eventFailureData) {
print('[Adjust]: Event tracking failure!');

if (eventFailureData.eventToken != null) {
Expand All @@ -226,16 +215,13 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (eventFailureData.jsonResponse != null) {
print('[Adjust]: JSON response: ' + eventFailureData.jsonResponse!);
}
};

config.deferredDeeplinkCallback = (String? uri) {
}).setDeferredDeeplinkCallback((String? uri) {
print('[Adjust]: Received deferred deeplink: ' + uri!);
};

config.skanUpdatedCallback = (Map<String, String> skanUpdateData) {
}).setSkanUpdatedCallback((Map<String, String> skanUpdateData) {
print('[Adjust]: Received SKAN update information!');
if (skanUpdateData["conversion_value"] != null) {
print('[Adjust]: Conversion value: ' + skanUpdateData["conversion_value"]!);
print('[Adjust]: Conversion value: ' +
skanUpdateData["conversion_value"]!);
}
if (skanUpdateData["coarse_value"] != null) {
print('[Adjust]: Coarse value: ' + skanUpdateData["coarse_value"]!);
Expand All @@ -246,7 +232,7 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
if (skanUpdateData["error"] != null) {
print('[Adjust]: Error: ' + skanUpdateData["error"]!);
}
};
});

// Add session callback parameters.
Adjust.addGlobalCallbackParameter('scp_foo_1', 'scp_bar');
Expand Down Expand Up @@ -381,9 +367,9 @@ class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
value: _isSdkEnabled,
onChanged: (bool value) {
setState(() {
if(value == true){
if (value == true) {
Adjust.enable();
}else {
} else {
Adjust.disable();
}
_isSdkEnabled = value;
Expand Down
24 changes: 11 additions & 13 deletions example/lib/util.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:adjust_sdk/adjust_event.dart';
import 'package:adjust_sdk/adjust_extensions.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -63,28 +64,25 @@ class Util {
}

static AdjustEvent buildSimpleEvent() {
return new AdjustEvent(EVENT_TOKEN_SIMPLE);
return AdjustEventBuilder.create(EVENT_TOKEN_SIMPLE);
}

static AdjustEvent buildRevenueEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_REVENUE);
event.setRevenue(100.0, 'EUR');
event.transactionId = 'DummyTransactionId';
return event;
return AdjustEventBuilder.create(EVENT_TOKEN_REVENUE)
.withRevenue(100.0, 'EUR')
.withTransactionId('DummyTransactionId');
}

static AdjustEvent buildCallbackEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_CALLBACK);
event.addCallbackParameter('key1', 'value1');
event.addCallbackParameter('key2', 'value2');
return event;
return AdjustEventBuilder.create(EVENT_TOKEN_CALLBACK)
.withCallbackParameter('key1', 'value1')
.withCallbackParameter('key2', 'value2');
}

static AdjustEvent buildPartnerEvent() {
AdjustEvent event = new AdjustEvent(EVENT_TOKEN_PARTNER);
event.addPartnerParameter('foo1', 'bar1');
event.addPartnerParameter('foo2', 'bar2');
return event;
return AdjustEventBuilder.create(EVENT_TOKEN_PARTNER)
.withPartnerParameter('foo1', 'bar1')
.withPartnerParameter('foo2', 'bar2');
}

static void showMessage(
Expand Down
231 changes: 231 additions & 0 deletions lib/adjust_extensions.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
import 'package:adjust_sdk/adjust_third_party_sharing.dart';

import 'adjust_config.dart';
import 'adjust_event.dart';

extension AdjustEventBuilder on AdjustEvent {
static AdjustEvent create(String token) {
return AdjustEvent(token);
}

AdjustEvent withRevenue(num revenue, String currency) {
this.setRevenue(revenue, currency);
return this;
}

AdjustEvent withCallbackParameter(String key, String value) {
this.addCallbackParameter(key, value);
return this;
}

AdjustEvent withPartnerParameter(String key, String value) {
this.addPartnerParameter(key, value);
return this;
}

AdjustEvent withCallbackId(String callbackId) {
this.callbackId = callbackId;
return this;
}

AdjustEvent withDeduplicationId(String deduplicationId) {
this.deduplicationId = deduplicationId;
return this;
}

AdjustEvent withProductId(String productId) {
this.productId = productId;
return this;
}

AdjustEvent withTransactionId(String transactionId) {
this.transactionId = transactionId;
return this;
}

AdjustEvent withPurchaseToken(String purchaseToken) {
this.purchaseToken = purchaseToken;
return this;
}
}

extension AdjustConfigBuilder on AdjustConfig {
static AdjustConfig create(String appToken, AdjustEnvironment environment) {
return new AdjustConfig(appToken, environment);
}

AdjustConfig withUrlStrategy(List<String> urlStrategyDomains,
bool useSubdomains, bool isDataResidency) {
this.setUrlStrategy(urlStrategyDomains, useSubdomains, isDataResidency);
return this;
}

AdjustConfig setSkanAttributionEnabled(bool isSkanAttributionEnabled) {
this.isSkanAttributionEnabled = isSkanAttributionEnabled;
return this;
}

AdjustConfig setSendingInBackgroundEnabled(
bool isSendingInBackgroundEnabled) {
this.isSendingInBackgroundEnabled = isSendingInBackgroundEnabled;
return this;
}

AdjustConfig setAdServicesEnabled(bool isAdServicesEnabled) {
this.isAdServicesEnabled = isAdServicesEnabled;
return this;
}

AdjustConfig setIdfaReadingEnabled(bool isIdfaReadingEnabled) {
this.isIdfaReadingEnabled = isIdfaReadingEnabled;
return this;
}

AdjustConfig setIdfvReadingEnabled(bool isIdfvReadingEnabled) {
this.isIdfvReadingEnabled = isIdfvReadingEnabled;
return this;
}

AdjustConfig setCostDataInAttributionEnabled(
bool isCostDataInAttributionEnabled) {
this.isCostDataInAttributionEnabled = isCostDataInAttributionEnabled;
return this;
}

AdjustConfig setPreinstallTrackingEnabled(bool isPreinstallTrackingEnabled) {
this.isPreinstallTrackingEnabled = isPreinstallTrackingEnabled;
return this;
}

AdjustConfig setLinkMeEnabled(bool isLinkMeEnabled) {
this.isLinkMeEnabled = isLinkMeEnabled;
return this;
}

AdjustConfig setDeviceIdsReadingOnceEnabled(
bool isDeviceIdsReadingOnceEnabled) {
this.isDeviceIdsReadingOnceEnabled = isDeviceIdsReadingOnceEnabled;
return this;
}

AdjustConfig setCoppaComplianceEnabled(bool isCoppaComplianceEnabled) {
this.isCoppaComplianceEnabled = isCoppaComplianceEnabled;
return this;
}

AdjustConfig setPlayStoreKidsComplianceEnabled(
bool isPlayStoreKidsComplianceEnabled) {
this.isPlayStoreKidsComplianceEnabled = isPlayStoreKidsComplianceEnabled;
return this;
}

AdjustConfig setDeferredDeeplinkOpeningEnabled(
bool isDeferredDeeplinkOpeningEnabled) {
this.isDeferredDeeplinkOpeningEnabled = isDeferredDeeplinkOpeningEnabled;
return this;
}

AdjustConfig setAttConsentWaitingInterval(num attConsentWaitingInterval) {
this.attConsentWaitingInterval = attConsentWaitingInterval;
return this;
}

AdjustConfig setEventDeduplicationIdsMaxSize(
num eventDeduplicationIdsMaxSize) {
this.eventDeduplicationIdsMaxSize = eventDeduplicationIdsMaxSize;
return this;
}

AdjustConfig setSdkPrefix(String sdkPrefix) {
this.sdkPrefix = sdkPrefix;
return this;
}

AdjustConfig setDefaultTracker(String defaultTracker) {
this.defaultTracker = defaultTracker;
return this;
}

AdjustConfig setExternalDeviceId(String externalDeviceId) {
this.externalDeviceId = externalDeviceId;
return this;
}

AdjustConfig setProcessName(String processName) {
this.processName = processName;
return this;
}

AdjustConfig setPreinstallFilePath(String preinstallFilePath) {
this.preinstallFilePath = preinstallFilePath;
return this;
}

AdjustConfig setFbAppId(String fbAppId) {
this.fbAppId = fbAppId;
return this;
}

AdjustConfig setLogLevel(AdjustLogLevel logLevel) {
this.logLevel = logLevel;
return this;
}

AdjustConfig setAttributionCallback(AttributionCallback attributionCallback) {
this.attributionCallback = attributionCallback;
return this;
}

AdjustConfig setSessionSuccessCallback(
SessionSuccessCallback sessionSuccessCallback) {
this.sessionSuccessCallback = sessionSuccessCallback;
return this;
}

AdjustConfig setSessionFailureCallback(
SessionFailureCallback sessionFailureCallback) {
this.sessionFailureCallback = sessionFailureCallback;
return this;
}

AdjustConfig setEventSuccessCallback(
EventSuccessCallback eventSuccessCallback) {
this.eventSuccessCallback = eventSuccessCallback;
return this;
}

AdjustConfig setEventFailureCallback(
EventFailureCallback eventFailureCallback) {
this.eventFailureCallback = eventFailureCallback;
return this;
}

AdjustConfig setDeferredDeeplinkCallback(
DeferredDeeplinkCallback deferredDeeplinkCallback) {
this.deferredDeeplinkCallback = deferredDeeplinkCallback;
return this;
}

AdjustConfig setSkanUpdatedCallback(SkanUpdatedCallback skanUpdatedCallback) {
this.skanUpdatedCallback = skanUpdatedCallback;
return this;
}
}

extension AdjustThirdPartySharingBuilder on AdjustThirdPartySharing {
static AdjustThirdPartySharing create(bool isEnabled) {
return new AdjustThirdPartySharing(isEnabled);
}

AdjustThirdPartySharing addGranularOption(
String partnerName, String key, String value) {
this.addGranularOption(partnerName, key, value);
return this;
}

AdjustThirdPartySharing addPartnerSharingSetting(
String partnerName, String key, bool value) {
this.addPartnerSharingSetting(partnerName, key, value);
return this;
}
}