event_analysis_library 1.0.5 event_analysis_library: ^1.0.5 copied to clipboard
Pinwheel event analysis library.
Event Analysis Package #
Getting Started #
First, add the event_analysis_library package to your pubspec dependencies.
To import PineWheel:
import 'package:event_analysis_library/event_analysis_library.dart';
Add the following permission on android manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
Add the following permission on info.plist:
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location when in the background.</string>
Add the following to your Podfile file:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',
## dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',
]
end
end
end
To use the package, create a singleton class:
import 'package:event_analysis_library/event_analysis_library.dart';
class AnalysisSdk {
factory AnalysisSdk() {
return _instance;
}
AnalysisSdk._internal();
static final AnalysisSdk _instance = AnalysisSdk._internal();
CreateEvent? _createEvent;
bool? result;
initializeSdk({required String locale}) async {
_createEvent = CreateEvent(productKey: 'bigmart-mobile', locale: locale);
result = await _createEvent!.initialize();
return result;
}
postEvent(String eventType, String eventValue, String userId, var offset) async {
if(result!){
await _createEvent!.postEvent(eventType: eventType, eventValue: eventValue, userId: userId, position: offset);
}else{
result = await initializeSdk(locale: 'en_us');
await _createEvent!.postEvent(eventType: eventType, eventValue: eventValue, userId: userId, position: offset);
}
}
userIdentity(String userId) async {
if(result!){
await _createEvent!.userIdentity(userId);
}else{
result = await initializeSdk(locale: 'en_us');
await _createEvent!.userIdentity(userId);
}
}
}
Note: Provide the product key on initialize sdk as per required.
Initialize SDK on main and provide the current locale used
await AnalysisSdk().initializeSdk(locale: "en_US");
Call userIdentity while use logs into the app
await AnalysisSdk().userIdentity('123123');
Call postEvent on required events like button clicks. Provide the event type. For example: button clicks, Navigation. Also get the position of the item clicked and send the value on position field.
var offset = _getPositions(context);
await AnalysisSdk().postEvent("BUTTON CLICK", "EVENT VALUE", 'USER ID', offset);
_getPositions(BuildContext context, GlobalKey key) {
final RenderBox? renderBox = key.currentContext!.findRenderObject() as RenderBox?;
final offSet = renderBox!.localToGlobal(Offset.zero);
return offSet;
}