Last updated:
0 purchases
mbf universal sdk
MBFUniversalSDK #
MBF Ads and Analytics Framework
Installation #
To install MBFUniversalSDK, run the following commands:
flutter pub add mbf_universal_sdk
copied to clipboard
iOS #
You need to add the following code to your Info.plist file and replace FILL_YOUR_WRITE_KEY_HERE with your write key:
<key>MBFSDKConfig</key>
<dict>
<key>writeKey</key>
<string>FILL_YOUR_WRITE_KEY_HERE</string>
</dict>
copied to clipboard
By default, we use the same write key for both ads and analytics. If you want to use a different write key for ad network, you can add another key-value pair like this:
<key>MBFSDKConfig</key>
<dict>
<key>writeKey</key>
<string>FILL_YOUR_WRITE_KEY_HERE</string>
<key>writeKeyForAdNetwork</key>
<string>FILL_YOUR_WRITE_KEY_HERE</string>
</dict>
copied to clipboard
Import the MBFUniversalSDK module in your UIApplicationDelegate
#import <WebKit/WebKit.h>
#import <MBFUniversalSDK/MBFUniversalSDK-Swift.h>
copied to clipboard
Configure a MBFUniversalSDK shared instance in your app delegate's application(_:didFinishLaunchingWithOptions:) method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[MBF startWithConfig:nil];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
copied to clipboard
Android #
You need to add the following code to your app manifest file, inside the
<meta-data
android:name="vn.mobifone.sdk.WRITE_KEY"
android:value="FILL_YOUR_WRITE_KEY_HERE" />
copied to clipboard
By default, we use the same write key for both ads and analytics. If you want to use a different write key for ad network, you can add another meta-data like this:
<meta-data
android:name="vn.mobifone.sdk.WRITE_KEY"
android:value="FILL_YOUR_WRITE_KEY_HERE" />
<meta-data
android:name="vn.mobifone.sdk.WRITE_KEY_ADNETWORK"
android:value="FILL_YOUR_WRITE_KEY_HERE" />
copied to clipboard
Usage #
AdNetwork #
Banner Ad
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
// ...
BannerAd(
size: AdSize.custom("320x100"),
unitID: <YOUR_INVENTORY_ID>,
request: const AdRequest(context: {
// This is optional
"title": "Got Talents show",
"keywords": "movie, show, hot",
"screen": "Home",
}),
listener: BannerAdListener(
onAdLoaded: () => print('FLT onAdLoaded'),
onAdFailedToLoad: (error) => print('FLT onAdFailedToLoad: $error')
),
),
copied to clipboard
Predefined sizes:
AdSize
Width x Height
banner
320x50
fullBanner
468x60
largeBanner
320x100
rectangle
250x250
mediumRectangle
300x250
video
480x360
Or custom any size in format widthxheight. Example: 640x480, 300x500...
Adaptive Banner Ad
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
// ...
BannerAd(
size: AdSize.custom("320x150"),
unitID: <YOUR_INVENTORY_ID>,
adaptiveSize: <YOUR_ADAPTIVE_SIZE>, // SDK will calculate height automatically base on Ad ratio
request: const AdRequest(context: {
// This is optional
"title": "Got Talents show",
"keywords": "movie, show, hot",
"screen": "Home",
}),
listener: BannerAdListener(
onAdLoaded: () => print('FLT onAdLoaded'),
onAdFailedToLoad: (error) => print('FLT onAdFailedToLoad: $error')
),
),
copied to clipboard
Video Ad
To display a video ad, you need to use the VideoAdLoader function to get the vast tag URL from the MBF platform and then use your own player to play it.
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
// ...
try {
// Load the ad by calling the VideoAdLoader function and passing the inventory ID and ad type
var vastTagUrl = await VideoAdLoader.loadAd(YOUR_INVENTORY_ID, 'video');
print('FLT onAdLoader: $vastTagUrl');
// Then use your own player to play the retrieved vastTagUrl
} catch (error) {
// If an error occurs while loading the ad, print the error message
print('FLT onAdFailedToLoad: $error');
}
copied to clipboard
Analytics #
Analytics will be initialized automatically and collect data for you. You can also manually track events with the following methods:
Track Events
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
Analytics.track(String name, [Map<String, Object>? properties]);
copied to clipboard
To track an event, you need to call the Analytics.track() method and pass in two parameters: name and properties.
The name parameter is a string to name the event, for example: "Post view", "Sign up", "Purchase", etc.
The properties parameter is an object to contain detailed information about the event, for example: post title, product type, order value, etc.
// Create an object to contain the properties of the event
const postViewEventProperties = {
title: 'Post Title',
category: 'Category 1, Category 2',
keyword: 'Keyword 1, Keyword 2, ...',
...
};
// Track the event "Post view" with the properties created
Analytics.track('Post view', postViewEventProperties);
copied to clipboard
Identify Events
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
Analytics.identify(String userId, [Map<String, Object>? traits]);
copied to clipboard
To identify a user, you need to call the Analytics.identify() method and pass in one parameter: userId.
The userId parameter is a string to identify your user, for example: "PartnerUserID-01".
You can also pass in another object to contain additional information about the user, for example: user name, user type, etc.
// Create an object to contain the properties of the user
const userTraits = {
userName: 'Username 1',
userType: 'Normal',
...
};
// Identify user with user ID and properties created
Analytics.identify('PartnerUserID-01', userTraits)
copied to clipboard
Screen Events
import 'package:mbf_universal_sdk/mbf_universal_sdk.dart';
Analytics.screen(String title, [Map<String, Object>? properties]);
copied to clipboard
To track a screen, you need to call the Analytics.screen() method and pass in one parameter: title.
The title parameter is a string to name the screen, for example: "Login Screen", "Home Screen", etc.
You can also pass in another object to contain detailed information about the screen, for example: login method, number of posts, etc.
// Create an object to contain the properties of the screen
const loginScreenProperties = {
loginMethod: 'FACEBOOK/GOOGLE/OTP/QR',
...
};
// Track screen with screen name and properties created
Analytics.screen(title: "LoginScreen", properties: loginScreenProperties)
copied to clipboard
License #
MBFUniversalSDK is available under the MIT license. See the LICENSE file for more info.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.