deeplink_dev 2.2.5
deeplink_dev: ^2.2.5 copied to clipboard
deeplink.dev
example/lib/main.dart
import 'dart:async';
import 'dart:io';
import 'package:deeplink_dev/attribution_sdk_core.dart';
import 'package:deeplink_dev/in_app_event_key.dart';
import 'package:deeplink_dev/in_app_event_type.dart';
import 'package:deeplink_dev/sdk_callback.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
startSdk();
}
Future<void> startSdk() async {
if (Platform.isAndroid) {
/// [Optional] This property is used to identify the source of the installation package to better understand how users obtain the app.
/// You can set the property value before initializing the SDK. If not passed in or null is passed in, the default is empty
AttributionSdkCore.instance.setPackageSource("YOUR_PACKAGE_SOURCE");
/// [Optional] By default, the SDK will automatically obtain Gaid, and developers do not need to set it manually
/// You can set the property value before initializing the SDK.
AttributionSdkCore.instance.setGaid("ABCD-EFGH-IJKL-MNOP");
AttributionSdkCore.instance.enableAttributionListener();
} else if (Platform.isIOS) {
/// [Optional] If you can get campaign info from clipboard, set the clipboard info here
/// This can improve the success rate of attribution.
AttributionSdkCore.instance.setClipboardInfo("CLIPBOARD_INFO");
}
/// [Optional] Developers can enable IP detection callback to obtain the detected client IP
AttributionSdkCore.instance.enableIpListener();
/// [Optional] Defaults to false. You can set the property value before initializing the SDK.
/// When true is passed, it means that the developer wants to customize the device ID.
/// Attribution and events will be reported only when the developer passes in a custom device ID.
/// When false is passed, the SDK will generate the device ID internally.
AttributionSdkCore.instance.setWaitForDeviceId(true);
/// [Optional] By default, the SDK will automatically generate a device ID.
/// The custom device ID passed by the developer will take effect only when AttrSdk.setWaitForDeviceId is passed true.
AttributionSdkCore.instance.setDeviceId("A-B-C-D");
/// [Optional] Defaults to false. You can set the property value before initializing the SDK.
/// When true is passed, it means that the developer wants to customize the account ID to associate the account with the attribution information.
/// Attribution will be reported only if and when the developer passes in a customized account ID.
/// When false is passed, the SDK will not generate a account ID internally.
AttributionSdkCore.instance.setWaitForAccountId(true);
/// [Optional] Defaults to empty. Used to associate the account system in the developer's business logic with the attribution information.
AttributionSdkCore.instance.setAccountId("ACCOUNT_ID");
/// [Optional] Set user related information
AttributionSdkCore.instance.setUserInfo({
InAppEventKey.firstName: "FIRST_NAME",
InAppEventKey.lastName: "LAST_NAME",
InAppEventKey.countryName: "COUNTRY_NAME",
InAppEventKey.city: "CITY",
InAppEventKey.emails: ["EMAIL1", "EMAIL2"],
InAppEventKey.phones: ["PHONE1", "PHONE2"],
InAppEventKey.fbLoginId: "FB_LOGIN_ID"
});
AttributionSdkCore.instance
.setSdkCallback(SdkCallback(onSdkInitCompleted: (int code) {
if (kDebugMode) {
print("onSdkInitCompleted code:$code");
}
_logCampaignInfo();
if (code == 0) {
/// Initialization successful
_logEvents();
/// Developers can attribute activation by reporting deeplink-activated content
if (Platform.isAndroid) {
AttributionSdkCore.instance
.trackAppReEngagement("YOUR_DEEPLINK_INFO");
}
} else {
/// Initialization failed, for specific failure reasons refer to the code interpretation
}
}, onAttributionSuccess: (Map<String, dynamic> attribution) {
/// Obtain attribution results successfully
if (kDebugMode) {
print("onAttributionSuccess");
}
_logCampaignInfo();
}, onAttributionFailed: (int code) {
/// Failed to obtain attribution results
}, onIpDetected: (List<String> ipList) {
/// Obtain the detected client IP
if (kDebugMode) {
for (var ip in ipList) {
print("ip:$ip");
}
}
}));
AttributionSdkCore.instance.initSdk(
"ACCOUNT_ID", "DEV_TOKEN", "APPLE_STORE_ID",
metaAppId: "[Optional]META_APP_ID",
appsFlyerAppId: "[Optional]APPS_FLYER_APP_ID",
appsFlyerDevKey: "[Optional]APPS_FLYER_DEV_KEY");
AttributionSdkCore.instance.launch();
}
/// You can also directly call and obtain the attribution information after the SDK is initialized.
/// It should be noted that the method for directly obtaining attribution results will return local cache,
/// so if the local cache has not been generated, the attribution result will be null.
Future<void> _logCampaignInfo() async {
if (kDebugMode) {
Map<String, dynamic>? campaignInfo =
await AttributionSdkCore.instance.getAttributionInfo();
print("campaignInfo :$campaignInfo");
}
}
Future<void> _logEvents() async {
_logAddToCartEvent();
_logAddToWishlistEvent();
_logInitiateCheckOutEvent();
_logPurchaseEvent();
_logSubscribeEvent();
_logSearchEvent();
_logViewContentEvent();
}
//You can report this event when a user adds an item to the shopping cart.
_logAddToCartEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.addToCart,
_generateProductInfo(
//[require] Currency Unit
currency: "USD",
//[require] Total amount of all products
totalValue: "9.9",
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
// Please fill in at least one of skuId and productId
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend.
// Please fill in at least one of skuId and productId
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product that the user added to the shopping cart
InAppEventKey.productName: "PRODUCT_NAME",
//[require] Quantity of the product
InAppEventKey.quantity: "1",
//[require] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
//You can report this event when a user adds an item to their wishlist.
_logAddToWishlistEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.addToWishList,
_generateProductInfo(
//[optional] Currency Unit
currency: "USD",
//[optional] Total amount of all products
totalValue: "9.9",
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend.
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product that the user added to wishlist
InAppEventKey.productName: "PRODUCT_NAME",
//[optional] Quantity of the product
InAppEventKey.quantity: "1",
//[optional] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
// You can report this event when a user enters the checkout process
// but the checkout process has not been completed
_logInitiateCheckOutEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.initiateCheckOut,
_generateProductInfo(
//[require] Currency Unit
currency: "USD",
//[require] Total amount of goods
totalValue: "9.9",
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
// Please fill in at least one of skuId and productId
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend.
// Please fill in at least one of skuId and productId
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product that the user want to buy
InAppEventKey.productName: "PRODUCT_NAME",
//[require] Quantity of the product
InAppEventKey.quantity: "1",
//[require] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
// You can report this event when a user completes a purchase or checkout process.
_logPurchaseEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.purchase,
_generateProductInfo(
//[require] The order number corresponding to the order
orderNo: "ORDER_NO_${DateTime.now().millisecond}",
//[require] Currency Unit
currency: "USD",
//[require] Total amount of goods
totalValue: "9.9",
//[require] The time when the product was purchased, in seconds
purchaseDate: DateTime.now().second.toString(),
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
// Please fill in at least one of skuId and productId
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend
// Please fill in at least one of skuId and productId
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product that the user purchased
InAppEventKey.productName: "PRODUCT_NAME",
//[require] Quantity of the product
InAppEventKey.quantity: "1",
//[require] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
// You can report this event when a user applies to start paying for a product
// or service you provide.
_logSubscribeEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.subscribe,
_generateProductInfo(
//[require] The order number corresponding to the order
orderNo: "ORDER_NO_${DateTime.now().millisecond}",
//[require] The validity period of the subscription product, in days
subscribeDay: "30",
//[require] Currency Unit
currency: "USD",
//[require] Total amount of goods
totalValue: "29.9",
//[require] The time when the product was purchased, in seconds
purchaseDate: DateTime.now().second.toString(),
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
// Please fill in at least one of skuId and productId
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend
// Please fill in at least one of skuId and productId
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product that the user purchased
InAppEventKey.productName: "PRODUCT_NAME",
//[require] Quantity of the product
InAppEventKey.quantity: "1",
//[require] Total amount of the product
InAppEventKey.value: "29.9"
}
]));
}
//You can report this event when a user searches for a product.
_logSearchEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.search,
_generateProductInfo(
//[require] What users searched for
searchContent: "SEARCH_CONTENT",
//[optional] Currency Unit
currency: "USD",
//[optional] Total amount of goods
totalValue: "9.9",
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product selected from the search results
InAppEventKey.productName: "PRODUCT_NAME",
//[optional] Quantity of the product
InAppEventKey.quantity: "1",
//[optional] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
// You can report this event when a user visits a web page you care about
// (for example, a product page or a landing page).
_logViewContentEvent() {
AttributionSdkCore.instance.logEvent(
InAppEventType.viewContent,
_generateProductInfo(
//[optional] Currency Unit
currency: "USD",
//[optional] Total amount of goods
totalValue: "9.9",
[
{
//[optional] The product ID of the store (Google Store, Apple Store) backend.
// Please fill in at least one of skuId and productId
InAppEventKey.skuId: "SKU_ID",
//[optional] The product ID of the developer's business backend
// Please fill in at least one of skuId and productId
InAppEventKey.productId: "PRODUCT_ID",
//[optional] The name of the product the user viewed
InAppEventKey.productName: "PRODUCT_NAME",
//[optional] Quantity of the product
InAppEventKey.quantity: "1",
//[optional] Total amount of the product
InAppEventKey.value: "9.9"
}
]));
}
Map<String, dynamic> _generateProductInfo(List<Map> products,
{String? orderNo,
String? currency,
String? totalValue,
String? searchContent,
String? subscribeDay,
String? purchaseDate}) {
return {
InAppEventKey.orderNo: orderNo,
InAppEventKey.currency: currency,
InAppEventKey.value: totalValue,
InAppEventKey.products: products,
InAppEventKey.searchContent: searchContent,
InAppEventKey.subscribeDay: subscribeDay,
InAppEventKey.purchaseDate: purchaseDate
};
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('AttributionFlutterPlugin'),
),
body: const Center(),
),
);
}
}