tracker_flutter 2.3.1
tracker_flutter: ^2.3.1 copied to clipboard
A flutter plugin for tracking events from Flutter. The given events will be sent to the native Tracker library.
tracker_flutter #
A flutter plugin for tracking events from Flutter. The given events will be sent to the native (Android and iOS) Tracker library.
Installation #
Add dependency to your pubspec.yaml file #
Add tracker_flutter
as a dependency in your pubspec.yaml
file.
Android #
Open the android project inside the android
folder of your project in Android studio
.
1. Add token to get Terra libraries
Add TekoGoogleRegistryToken to the local.properties
file (contact trung.cs@teko.vn to get
the token).
// android/local.properties
TekoGoogleRegistry.password=<your-token>
In project build.grade
(android/build.gralde
file). Add the following code:
// android/build.gradle
allprojects {
repositories {
...
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
maven {
setUrl("https://asia-southeast1-maven.pkg.dev/teko-development/teko-mobile-sdks")
authentication {
basic(BasicAuthentication)
}
credentials {
username = "_json_key_base64"
password = properties.getProperty('TekoGoogleRegistry.password')
}
}
}
}
iOS #
Open the ios
project insdie the android folder of your project in xcode
.
1. Setup github access token for accessing Teko iOS frameworks
Please contact Terra team to get the token.
Add new environment variable to your computer with the following key: GITHUB_USER_TOKEN
.
2. Set up the Podfile
- At the beginning of your Podfile, define the source:
// on local machine
source 'https://github.com/teko-vn/Specs-ios.git'
// on CI environment
source 'https://' + ENV['GITHUB_USER_TOKEN'] + '@github.com/teko-vn/Specs-ios.git'
- Configure targets for frameworks
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
# set valid architecture
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s x86_64'
# Xcode12 have to exclude arm64 for simulator architecture
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
end
end
end
Normally, in the Podfile
there is the following code:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
In this case, we update the existing code to:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
# new code
target.build_configurations.each do |config|
# set valid architecture
config.build_settings['VALID_ARCHS'] = 'arm64 armv7 armv7s x86_64'
# Xcode12 have to exclude arm64 for simulator architecture
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
end
# end of new code
end
end
Note: please do not commit <your_token_secret> to github or it will be revoked
Library usage #
Initialize/get an TerraTracker instance #
Static Method: TerraTracker.getInstance(String appName) → Future<TerraTracker>
Should be called in initialize phase of your app and must be called after initilizing TerraApp successful.
Set user info #
Method: TerraTracker.setUserInfo({String userId, String? phoneNumber}) → void
This info are tracked in every events. You should pass userId
to tracker lib as soon as you identified the user. The phoneNumber
is optional.It will be sent to network.phoneNumber
param in the event.
Track alert event #
These events indicate that an popup message is showing, require user click to dismiss or make decision.
Method: TerraTracker.trackAlertEvent(AlertEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackAlertEvent(
AlertEventBody(
alertType: AlertType.popUp,
alertMessage: "testAlertMessage",
),
);
Track cart event #
There events indicate user interactions with cart.
Method: TerraTracker.trackCartEvent(CartEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackCartEvent(
CartEventBody(
eventName: CartEventName.addToCart,
cartId: "testCartId",
skuId: "210801335",
skuName: "testSkuName",
price: 100000,
quantity: 10,
status: Status.success,
),
);
Track checkout event #
There events indicate user interactions with cart.
Method: TerraTracker.trackCheckoutEvent(CheckoutEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackCheckoutEvent(
CheckoutEventBody(
orderId: "orderId",
amountBeforeDiscount: 100000.0,
amountAfterDiscount: 90000.0,
discountAmount: 10000.0,
products: [
Product(
skuId: "skuId_1",
skuName: "skuName_1",
price: 25500.0,
promotionPrice: 25500.0,
quantity: 10),
Product(
skuId: "skuId_2",
skuName: "skuName_2",
price: 50000.0,
promotionPrice: 50000.0,
quantity: 2),
],
paymentMethod: PaymentMethod.cash,
status: Status.success,
tax: 10.0,
shippingFee: 25000.00,
shippingAddressCode: "1000",
note: "test note",
),
);
Track custom event #
Use this event to track anything you need.
Method: TerraTracker.trackCustomEvent(CustomEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackCustomEvent(
CustomEventBody(
category: "testCategory",
action: "testAction",
label: "testLabel",
property: "testProperty",
value: 99,
),
);
Track error event #
These events indicate that network exceptions have occurred.
Method: TerraTracker.trackErrorEvent(ErrorEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackErrorEvent(
ErrorEventBody(
apiCall: "https://error-api.abc",
httpResponseCode: 200,
errorSource: ErrorSource.http,
errorCode: "40001",
errorMessage: "testErrorMessage",
apiPayload: "{\"sku\":\"123456\"}",
responseJson: "{\"code\":\"403\",\"message\":\"No permission to access\"}",
),
);
Track interaction event #
These events indicate user interactions with app, like clicking on buttons.
Method: TerraTracker.trackInteractionEvent(InteractionContentEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackInteractionEvent(
InteractionContentEventBody(
interaction: Interaction.click,
regionName: "testRegionName",
contentName: "testContentName",
target: "testTarget",
payload: "{\"example\":\"payload\"}",
),
);
Track payment event #
These events indicate the user action related to payment.
Method: TerraTracker.trackPaymentEvent(PaymentEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackPaymentEvent(
PaymentEventBody(
orderId: "orderId",
amount: 1000000,
paymentMethod: PaymentMethod.cash,
status: Status.failed,
statusCode: 10000,
),
);
Track scan event #
These events indicate the user action related to scan.
Method: TerraTracker.trackScanEvent(ScanEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackScanEvent(
ScanEventBody(
scanId: "scanId",
regionName: "testRegionName",
target: "testTarget",
),
);
Track screen view event #
There events indicate user view/exit a screen in your app.
Method: TerraTracker.trackScreenViewEvent(ScreenViewEventBody body) → void
final terraTracker = await TerraTracker.getInstance(terraAppName);
terraTracker.trackScreenViewEvent(
ScreenViewEventBody(
eventName: ScreenEventName.enterScreenView, // enter or exit screen
screenName: "home", // new screen just displayed to user
contentType: "banner", // screen type, somewhat the group that this screen belongs to
referrer: "refererScreen", // the screen before we enter this screen
),
);
Track page loading time #
These events indicate the loading time of a specific page.
Method: TerraTracker.trackPageLoadingTime()
final startTimeInMilis = currentTime;
// Loading page
final loadingTime = currentTime - startTimeInMilis;
// Track loading time
terraTracker.trackPageLoadingTime(
screenName: 'Test Screen Name',
pageLoadTimeInMillis: loadingTime,
sdkId: "...",
sdkVersion: "...",
);