nudge_core 0.0.1 nudge_core: ^0.0.1 copied to clipboard
The Official core package to enable Nudge tracking and in-app experiences in your Flutter app by Nudge (www.nudgenow.com).
Overview #
The Nudge Flutter Package allows you to integrate scratch card games provided by Nudge into your Flutter application. With this package, you can engage your users with interactive games and promotions.
Getting Started #
To get started with the Nudge Flutter Package, follow these steps:
- Navigate to Nudge's official website to explore the games that you can render through scratch cards.
- Register your product on our website Nudge.
- From the Nudge website, you will obtain a unique secret key. Use this secret key while initializing the package.
Usage #
After adding the NudgeCore package to your project's dependencies in the pubspec.yaml file, you need to run flutter pub get command to fetch the package and make it accessible in your Flutter project. This command will download the package and its dependencies, allowing you to import and utilize the Nudge package in your code.
To initialize the NudgeCore class with a reusable variable name and access all its functions through it, follow these steps:
Import the NudgeCore package into your Dart file:
import 'package:nudge_core/nudge_core.dart';
Create an instance of the NudgeCore class with your desired variable name and add:
token
(required): The secret key obtained from the Nudge website, used for authentication.
final core = NudgeCore(<TOKEN>);
Nudge Provider #
The NudgeProvider
is a Flutter widget that should be wrapped around the main MaterialApp
widget in your application. It enables integration with the Nudge package and requires two parameters: app
and child
.
Parameters #
-
app
(required): An instance of the Nudge core initialized with your unique token. The Nudge core manages your application's integration with the Nudge platform. -
child
(required): The child widget, typically theMaterialApp
widget, that will be rendered below theNudgeProvider
. It should include thenavigatorKey
parameter.
Example
return NudgeProvider(
nudgeInstance: core,
child: MaterialApp(
navigatorKey: NudgeProviderState.navigatorKey,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
),
);
The NudgeProvider now offers an optional parameter: plugins. These parameters allow you to initialize and utilize Nudge's scratch card and survey packages in addition to the core functionality. Here's an example of how you can use them:
Example
final scratch = ScratchCardUi(<token>);
final survey = SurveyUI(token: token);
Add them to nudge provider as follows
return NudgeProvider(
app: core,
plugins: [
scratch,
survey
],
child: MaterialApp(
navigatorKey: NudgeProviderState.navigatorKey,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
),
);
When a task related to the corresponding entry points is triggered, the associated functionality will be activated and presented to the user.
Initializing session #
Whenever a distinct user Id which is used to identify users at the client's end is defined, call the initSession function to initialize the user session.
await core.initSession(externalId:'CLIENT_IDENTIFIABLE_USER_ID');
You can also send more user attributes along with the user ID for making segments of audiences.
await core.initSession('CLIENT_IDENTIFIABLE_USER_ID',
properties: <String, dynamic>{
"name": "Client User 1",
"age": 27,
"gender": "M",
"country":"US",
});
Start Tracking Events #
Make shure you have initialized sesstion before tracking
To track an event, simply call
await core.track(type:'EVENT_TYPE');
This will also lead you to Survey or ScratchCards depending upon the preSetup of case sensetive event keys on dashboard.
You can also add event properties for analytics and .making segments of users based on the properties of their events performed for custom audience experiences.
await core.track(type:'EVENT_TYPE',
properties: <String, dynamic>{
"product": "Fortune Cookies",
"quantity": 5,
"countryOfExport":"US",
});
Callback Funiction #
The getCallBack
function from the Nudge class enables you to set up a callback mechanism to receive notifications from any screen within the Nudge package. This feature proves particularly useful when handling specific actions or events, such as a Call-to-Action (CTA) callback following a scratch card, which includes a URL link to redirect the user to a desired location.
Example:
void openlink(String url) {
print(url);
}
scratch.getCallBack(openlink);
Also for survey
Example:
void openlink(String url) {
print(url);
}
survey.getCallBack(openlink);
Setting up Back Icons #
setIcons
allows you to set Icons of your choise on top of the screens.
By default they are < and ✖
Example:
scratch.setIcons(
topLeft : (icon of your choice),
topRight:(icon of your choice),
);