adstart_flutter_sdk 0.1.2
adstart_flutter_sdk: ^0.1.2 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}');
}
},
);
// 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.categoryViewed(name: 'Category name');
await adstart.brandViewed(name: 'Brand name');
await adstart.searchedFor(searchTerm: 'black shoes');
debugPrint('Adstart session: $sessionId');
adstart.dispose();
}