moengage_personalize 1.0.0
moengage_personalize: ^1.0.0 copied to clipboard
Flutter Plugin for using Personalize Experience feature of MoEngage Platform.
MoEngage Personalize Plugin #
Personalize Experience Plugin for MoEngage Platform
SDK Installation #
To add the MoEngage Flutter SDK to your application, edit your application's pubspec.yaml file and add the below dependency to it:
dependencies:
moengage_personalize: $latestSdkVersion
replace $latestSdkVersion with the latest SDK version.
Run flutter packages get to install the SDK.
Note: This plugin is dependent on moengage_flutter plugin. Make sure you have installed the moengage_flutter plugin as well.
Refer to the Documentation for complete integration guide.
Usage #
Initialization #
import 'package:moengage_personalize/moengage_personalize.dart';
final personalize = MoEngagePersonalize('<YOUR_APP_ID>');
Fetch experience metadata #
Retrieve metadata for all experiences matching the given statuses:
try {
final meta = await personalize.fetchExperiencesMeta(
[ExperienceStatus.active, ExperienceStatus.paused],
);
for (final exp in meta.experiences) {
print('${exp.experienceKey}: ${exp.status}');
}
} on PersonalizeError catch (e) {
print('Error: ${e.code} — ${e.message}');
}
Fetch experiences #
Fetch fully resolved experience campaigns by key:
try {
final result = await personalize.fetchExperiences(
['welcome_banner', 'home_hero'],
attributes: {'locale': 'en'},
);
for (final exp in result.experiences) {
print('${exp.experienceKey}: ${exp.payload}');
}
for (final failure in result.failures) {
print('Failed: ${failure.reason} for ${failure.experienceKeys}');
}
} on PersonalizeError catch (e) {
print('Error: ${e.code} — ${e.message}');
}
Fetch a single experience #
Convenience wrapper for a single key:
final result = await personalize.fetchExperience('welcome_banner');
Track experiences shown #
Call when one or more experience campaigns are rendered:
personalize.experiencesShown([experienceCampaign]);
Track experience clicked #
Call when the user interacts with an experience:
personalize.experienceClicked(experienceCampaign);
Track offerings shown #
Call when one or more offerings inside an experience are rendered:
personalize.offeringsShown([
{'offer_id': 'promo_123', 'position': '1'},
]);
Track offering clicked #
Call when the user clicks a specific offering:
personalize.offeringClicked(
experienceCampaign,
{'offer_id': 'promo_123'},
);