广告点击添加

This commit is contained in:
谢宇宁
2026-09-15 22:40:36 +07:00
parent d2a6c648e1
commit c5e5ec17df
9 changed files with 28 additions and 13 deletions
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:hgdj/assets_tool/images.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/hj_utils/screen.dart';
import 'package:hgdj/routers/jump_router.dart';
@@ -52,6 +53,7 @@ class TiktokSimpleCell extends StatelessWidget {
void _onTap() {
if (videoModel?.isRandomAd() == true) {
pushToPageByLink(videoModel?.randomAdsInfo?.href);
CommonService.adsClick(videoModel?.randomAdsInfo?.id);
return;
}
pushToVideoPage(videoModel: videoModel);
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/hj_utils/screen.dart';
import '../../../hj_model/video_model.dart';
@@ -77,6 +78,7 @@ class VideoHorCell extends StatelessWidget {
void _onTap() {
if (videoModel?.isRandomAd() == true) {
pushToPageByLink(videoModel?.randomAdsInfo?.href);
CommonService.adsClick(videoModel?.randomAdsInfo?.id);
return;
}
pushToVideoPage(videoModel: videoModel);
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:hgdj/assets_tool/images.dart';
import 'package:hgdj/config/config.dart';
import 'package:hgdj/extension/extensions.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/hj_utils/screen.dart';
import 'package:hgdj/routers/jump_router.dart';
import 'package:hgdj/tools_base/banner/ads_item.dart';
@@ -69,6 +70,7 @@ class VideoSimpleCell extends StatelessWidget {
void _onTap() {
if (videoModel?.isRandomAd() == true) {
pushToPageByLink(videoModel?.randomAdsInfo?.href);
CommonService.adsClick(videoModel?.randomAdsInfo?.id);
return;
}
if (_needVipUnlock) {
@@ -306,6 +308,7 @@ class _VideoSimpleAdsCellState extends State<VideoSimpleAdsCell> {
void _onAdTap() {
final ad = adsInfoArr![adIndex];
pushToPageByLink(ad.href);
CommonService.adsClick(ad.id);
}
@override
@@ -102,7 +102,6 @@ class RecommendAppPage extends StatelessWidget {
_buildVItem(AdsInfoModel item, int index) {
return AdsItem(
adInfo: item,
clickType: 0,
);
}
@@ -114,7 +113,6 @@ class RecommendAppPage extends StatelessWidget {
AdsItem(
adInfo: item,
showType: AdShowType.hor,
clickType: 0,
),
12.sizeBoxH,
],
@@ -125,7 +123,6 @@ class RecommendAppPage extends StatelessWidget {
return AdsItem(
adInfo: item,
showType: AdShowType.vImgText,
clickType: 0,
);
}
}
@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:hgdj/hj_model/video_model.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/routers/jump_router.dart';
import '../../../hj_model/splash/ads_model.dart';
@@ -14,7 +15,10 @@ class FeedAdView extends StatelessWidget {
Widget build(BuildContext context) {
final AdsInfoModel? adv = mediaInfo?.randomAdsInfo;
return GestureDetector(
onTap: () => pushToPageByLink(adv?.href),
onTap: () {
pushToPageByLink(adv?.href);
CommonService.adsClick(adv?.id);
},
// 强制全屏铺满(与视频页一致),避免 iOS 上未撑满导致显示不全
child: SizedBox.expand(
child: NetworkImageLoader(
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hgdj/hj_model/splash/ads_model.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/routers/jump_router.dart';
import 'package:hgdj/tools_base/ad_manager.dart';
import 'package:hgdj/tools_base/widget/net_image_widget.dart';
@@ -35,7 +36,10 @@ class _FloatAdViewState extends State<FloatAdView> {
clipBehavior: Clip.none,
children: [
GestureDetector(
onTap: () => pushToPageByLink(ad.href),
onTap: () {
pushToPageByLink(ad.href);
CommonService.adsClick(ad.id);
},
child: NetworkImageLoader(
imageUrl: cover,
width: 70,
+5 -1
View File
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hgdj/assets_tool/app_colors.dart';
import 'package:hgdj/assets_tool/images.dart';
import 'package:hgdj/hj_utils/api_service/common_service.dart';
import 'package:hgdj/hj_utils/screen.dart';
import '../../hj_model/splash/ads_model.dart';
@@ -72,7 +73,10 @@ class _SplashAdViewState extends State<SplashAdView> {
if (dataLen == 1) {
final ad = widget.adData!.first;
return GestureDetector(
onTap: () => pushToPageByLink(ad.href ?? ""),
onTap: () {
pushToPageByLink(ad.href ?? "");
CommonService.adsClick(ad.id);
},
child: Container(
alignment: Alignment.center,
child: NetworkImageLoader(
+5 -4
View File
@@ -225,11 +225,12 @@ class CommonService {
return result.isSuccess ? result.data : null;
}
//广告点击统计 广告类型 0:应用 1:广告
static Future<bool> adsClick(int? type) async {
/// 广告点击日志:[id] 广告 id(后端必填,空就不报);type 固定传 0(普通广告)
static Future<bool> adsClick(String? id) async {
if (id == null || id.isEmpty) return false;
final result = await httpManager.fetchResponseByPOST(
'/ads/click/stat',
param: {'type': type},
'/ads/click',
param: {'id': id, 'type': 0},
);
return result.isSuccess;
}
+1 -3
View File
@@ -22,7 +22,6 @@ class AdsItem extends StatefulWidget {
final double? aspectRatio;
final AdShowType? showType;
final double borderRadius;
final int clickType; //0:应用 1:广告
final Widget? child; //自定义子视图(IM 广告用)
final VoidCallback? onTap; //点击附加回调(IM 广告已读上报用)
@@ -32,7 +31,6 @@ class AdsItem extends StatefulWidget {
this.aspectRatio,
this.showType,
this.borderRadius = 12,
this.clickType = 1,
this.child,
this.onTap,
});
@@ -46,7 +44,7 @@ class _AdsItemState extends State<AdsItem> {
void _onTap() {
pushToPageByLink(adInfo.href);
CommonService.adsClick(widget.clickType);
CommonService.adsClick(adInfo.id);
widget.onTap?.call();
}