Adobe Analytics
Analyze your data from anywhere in the customer journey using your Adobe Analytics segments.
Contentsquare allows you to use your Adobe Analytics segments in every Contentsquare feature (Journey Analysis, Page Comparator, Zoning Analysis, Session Replay).
Prerequisite
Section titled Prerequisite- Follow the instructions from Adobe Analytics for mobile apps
- Add the
flutter_aepedge
package to your project and follow its instructions.
Code implementation
Section titled Code implementationAdd the following code snippet in your application code.
Add a call to the sendCSMatchingKeyIfNeeded()
from within the initState
of your application.
Listen to AppLifecycleState
change and call sendCSMatchingKeyIfNeeded()
when the application resumed.
import 'package:contentsquare/contentsquare.dart';import 'package:flutter_aepedge/flutter_aepedge.dart';// ... others imports
// TODO: Use your local storage. A package you can use is: https://pub.dev/packages/shared_preferencesfinal localStorage = LocalStorageFake();
@overridevoid initState() { // ... your code sendCSMatchingKeyIfNeeded(); WidgetsBinding.instance.addObserver(this); // ... your code}
@overridevoid dispose() { // ... your code WidgetsBinding.instance.removeObserver(this); super.dispose(); // ... your code}
@overridevoid didChangeAppLifecycleState(AppLifecycleState state) { super.didChangeAppLifecycleState(state); // Check if the app is in the foreground if (state == AppLifecycleState.resumed) { sendCSMatchingKeyIfNeeded(); }}
Future<void> sendCSMatchingKeyIfNeeded() async { // TODO: Implement your local storage. A package you can use is: https://pub.dev/packages/shared_preferences final csMatchingKeyTimestampMap = await localStorage.getMap( 'csMatchingKey_creation_ts', );
final csMatchingKeyIsNotGenerated = csMatchingKeyTimestampMap == null; if (csMatchingKeyIsNotGenerated) { await _submitNewCsMatchingKey(); return; }
final timestamp = DateTime.fromMillisecondsSinceEpoch( csMatchingKeyTimestampMap['timestamp'], ); if (DateTime.now().difference(timestamp).inMinutes > 30) { // if the key is not valid anymore, submit a new one await _submitNewCsMatchingKey(); } // if the key is still valid, do nothing}
Future<void> _submitNewCsMatchingKey() async { // Generate the matching key and store it in the local storage final millisecondsSinceEpoch = DateTime.now().millisecondsSinceEpoch; final csMatchingKeyValue = '${Random().nextDouble()}_$millisecondsSinceEpoch';
await localStorage.setMap('csMatchingKey_creation_ts', { 'csMatchingKey': csMatchingKeyValue, 'timestamp': millisecondsSinceEpoch, });
// Submit the matching key to Adobe final experienceEvent = ExperienceEvent({ 'xdmData': {'eventType': 'csMatchingKey_state'}, 'data': {'csMatchingKey': csMatchingKeyValue} }); await Edge.sendEvent(experienceEvent);
// Submit the matching key to Contentsquare await Contentsquare().sendDynamicVar( 'csMatchingKey', stringValue: csMatchingKeyValue, );}