adstart_flutter_sdk 0.1.4
adstart_flutter_sdk: ^0.1.4 copied to clipboard
Flutter SDK for Adstart event collection.
example/adstart_flutter_sdk_example.dart
import 'package:adstart_flutter_sdk/adstart_flutter_sdk.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/widgets.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// The integrating app owns the Firebase configuration for its business.
await Firebase.initializeApp();
final adstart = AdstartSdk(hashedId: 'your-hashed-id');
final sessionId = await adstart.init(
onPushEvent: (event) {
switch (event.type) {
case AdstartPushEventType.received:
debugPrint('Push received: ${event.notification?.title}');
case AdstartPushEventType.opened:
debugPrint('Push opened: ${event.deepLink}');
}
},
);
await adstart.signUp();
// Trigger this only from an explicit user action.
await adstart.requestPushPermission();
await adstart.customerIdentified(
CustomerIdentificationEventParams(
email: 'customer@example.com',
customerExternalId: 'customer-123',
),
);
final product = AdstartItem(
itemId: 'product-123',
itemName: 'Product name',
price: 249.90,
itemBrand: 'Brand name',
itemCategory: 'Category name',
);
final ecommerceParams = EcommerceEventParams(
currency: 'BRL',
items: <AdstartItem>[product],
);
await adstart.productViewed(ecommerceParams);
await adstart.addProductToCart(ecommerceParams);
await adstart.purchase(
PurchaseEventParams(
currency: ecommerceParams.currency,
items: ecommerceParams.items,
orderId: 'order-123',
shippingValue: 19.90,
),
);
await adstart.categoryViewed(name: 'Category name');
await adstart.brandViewed(name: 'Brand name');
await adstart.searchedFor(searchTerm: 'black shoes');
await adstart.screenVisited(
ScreenEventParams(
name: 'product_list',
attributes: <String, Object?>{
'filters': <Map<String, Object?>>[
<String, Object?>{
'field': 'brand',
'operator': 'equals',
'value': 'Nike',
},
],
},
),
);
await adstart.logout();
debugPrint('Adstart session: $sessionId');
adstart.dispose();
}