📢 推荐使用新版聚合插件GTAds,支持自定义广告插入
flutter_universalad是一款聚合字节跳动穿山甲flutter_unionad、腾讯优量汇(广点通)flutter_tencentad的聚合广告插件,方便直接调用多个厂商广告。体验demo
推荐参考以下插件的文档进行插件的集成。
[✓] Flutter (Channel stable, 3.16.6, on macOS 14.2.1 23C71 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] Android Studio (version 2023.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.3.2)
[✓] VS Code (version 1.85.2)
[✓] Connected device (4 available)
[✓] Network resources
flutter_universalad: ^latest
import 'package:flutter_universalad/flutter_universalad.dart';
await FlutterUniversalad.register(
pAndroidId: "5098580",
//穿山甲android id
pIosId: "5098580",
//穿山甲ios id
tAndroidId: "1200009850",
//优量汇android id
tIosId: "1200082163",
//优量汇ios id
appName: "Flutter_universalad",
//app名字
debug: true,
//是否显示日志
callBack: RegisterCallBack(pangolinInit: (result) {
setState(() {
_registerResult = "$_registerResult 穿山甲初始化 $result";
});
}, tencentInit: (result) {
setState(() {
_registerResult = "$_registerResult 优量汇初始化 $result";
_getVersion();
});
}),
);
VersionEntity versionEntity = await FlutterUniversalad.getSDKVersion();
_sdkVersion =
"穿山甲SDK ${versionEntity.pangolinVersion} 优量汇SDK ${versionEntity.tencentVersion}";
预加载激励广告
await FlutterUniversalad.loadRewardVideoAd(
//穿山甲广告android id
pAndroidId: "945418088",
//穿山甲广告ios id
pIosId: "945418088",
//优量汇广告android id
tAndroidId: "5042816813706194",
//优量汇广告ios id
tIosId: "8062535056034159",
//奖励名称
rewardName: "金币",
//奖励数量
rewardAmount: 10,
//用户id
userID: "123",
//交替加载
loadType: UniversalLoadType.INTURN,
//穿山甲出现的几率
probability: 0.5,
//扩展参数,开启服务器验证时上报
customData: "",
);
激励广告监听
FlutterUniversalAdStreamSubscription? _subscripti;
_subscripti = FlutterUniversalAdStream.initAdStream(
uRewardCallBack: URewardCallBack(
onShow: (sdkType) {
print("$sdkType 激励广告开始显示");
},
onFail: (sdkType, code, message) {
print("$sdkType 激励广告失败 $code $message");
},
onClick: (sdkType) {
print("$sdkType 激励广告点击");
},
onClose: (sdkType) {
print("$sdkType 激励广告关闭");
},
onReady: (sdkType) {
print("$sdkType 激励广告预加载完成");
FlutterUniversalad.showRewardVideoAd();
},
onUnReady: (sdkType) {
print("$sdkType 激励广告未预加载");
},
onVerify: (sdkType, transId, verify, amount, name) {
print(
"$sdkType 激励广告观看成功 transId=$transId verify=$verify amount=$amount name=$name");
},
),
);
//移除监听
@override
void dispose() {
super.dispose();
_subscription?.cancel();
}
展示激励广告
FlutterUniversalad.showRewardVideoAd();
预加载插屏广告
await FlutterUniversalad.loadInterstitialAd(
//穿山甲广告android id
pAndroidId: "946201351",
//穿山甲广告ios id
pIosId: "946201351",
//优量汇广告android id
tAndroidId: "9062813863614416",
//优量汇广告ios id
tIosId: "1052938046031440",
//是否全屏 仅优量汇起效
isFullScreen: false,
//交替加载
loadType: UniversalLoadType.INTURN,
//穿山甲出现的几率
probability: 0.5,
);
插屏广告监听
FlutterUniversalAdStreamSubscription? _subscripti;
_subscription = FlutterUniversalAdStream.initAdStream(
uInteractionCallBack: UInteractionCallBack(
onShow: (sdkType) {
print("$sdkType 插屏广告开始显示");
},
onFail: (sdkType, code, message) {
//只有两个插件都失败的情况下才会返回失败,只返回最后一次失败的参数,单独一个失败,会保底去拉取另一个sdk广告
print("$sdkType 插屏广告失败 $code $message");
},
onClick: (sdkType) {
print("$sdkType 插屏广告点击");
},
onClose: (sdkType) {
print("$sdkType 插屏广告关闭");
},
onReady: (sdkType) {
print("$sdkType 插屏广告预加载完成");
FlutterUniversalad.showInterstitialAd();
},
onUnReady: (sdkType) {
print("$sdkType 插屏广告未预加载");
},
),
);
//移除监听
@override
void dispose() {
super.dispose();
_subscription?.cancel();
}
展示插屏广告
FlutterUniversalad.showInterstitialAd();
FlutterUniversalad.splashAdView(
//穿山甲广告android id
pAndroidId: "887367774",
//穿山甲广告ios id
pIosId: "887367774",
//优量汇广告android id
tAndroidId: "4052216802299999",
//优量汇广告ios id
tIosId: "8012030096434021",
//广告加载模式 UniversalLoadType.INTURN 交替拉取广告,UniversalLoadType.RANDOWM 完全随机拉去广告
loadType: UniversalLoadType.INTURN,
//穿山甲出现的几率,UniversalLoadType.RANDOWM 起效,「0-1取值,0为不出现 1必出现」
probability: 0.5,
callBack: USplashCallBack(
onShow: (sdkType) {
print("$sdkType 开屏广告显示");
},
onFail: (sdkType, code, message) {
print("$sdkType 开屏广告失败 $code $message");
Navigator.pop(context);
},
onClick: (sdkType) {
print("$sdkType 开屏广告点击");
},
onClose: (sdkType) {
print("$sdkType 开屏广告关闭");
Navigator.pop(context);
},
)
FlutterUniversalad.nativeAdView(
//穿山甲广告android id
pAndroidId: "945417699",
//穿山甲广告ios id
pIosId: "945417699",
//优量汇广告android id
tAndroidId: "4072918853903023",
//优量汇广告ios id
tIosId: "7082132016439065",
width: 400.0,
height: 260.0,
//广告加载模式 UniversalLoadType.INTURN 交替拉取广告,UniversalLoadType.RANDOWM 完全随机拉去广告
loadType: UniversalLoadType.INTURN,
//穿山甲出现的几率,UniversalLoadType.RANDOWM 起效,「0-1取值,0为不出现 1必出现」
probability: 0.5,
callBack: UNativeCallBack(
onShow: (sdkType) {
print("$sdkType Native广告显示");
},
onFail: (sdkType, code, message) {
print("$sdkType Native广告失败 $code $message");
},
onClick: (sdkType) {
print("$sdkType Native广告点击");
},
onClose: (sdkType) {
print("$sdkType Native广告关闭");
},
),
)
FlutterUniversalad.bannerAdView(
//穿山甲广告android id
pAndroidId: "945410197",
//穿山甲广告ios id
pIosId: "945410197",
//优量汇广告android id
tAndroidId: "8042711873318113",
//优量汇广告ios id
tIosId: "6062430096832369",
width: 300.0,
height: 100.0,
//广告加载模式 UniversalLoadType.INTURN 交替拉取广告,UniversalLoadType.RANDOWM 完全随机拉去广告
loadType: UniversalLoadType.INTURN,
//穿山甲出现的几率,UniversalLoadType.RANDOWM 起效,「0-1取值,0为不出现 1必出现」
probability: 0.5,
callBack: UBannerCallBack(
onShow: (sdkType) {
print("$sdkType Banner广告显示");
},
onFail: (sdkType, code, message) {
print("$sdkType Banner广告失败 $code $message");
},
onClick: (sdkType) {
print("$sdkType Banner广告点击");
},
onClose: (sdkType) {
print("$sdkType Banner广告关闭");
},
),
)
插件 | 地址 |
---|---|
穿山甲广告插件 | flutter_unionad |
腾讯优量汇广告插件 | flutter_tencentad |
聚合广告插件 | flutter_universalad |
百度百青藤广告插件 | flutter_baiduad |
字节穿山甲内容合作插件 | flutter_pangrowth |
文档预览插件 | file_preview |
滤镜 | gpu_image |
Gromore聚合广告 | gromore |
- Email: gstory0404@gmail.com
- Blog:https://www.gstory.cn/