294 lines
7.2 KiB
Dart
294 lines
7.2 KiB
Dart
// Author: fengshengxiong
|
||
// Date: 2024/6/26
|
||
// Description: firebase_analytics管理
|
||
|
||
import 'package:firebase_analytics/firebase_analytics.dart';
|
||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||
import 'package:tone_snap/utils/log_util.dart';
|
||
import 'package:tone_snap/utils/obj_util.dart';
|
||
|
||
class FirebaseAnalyticsManager {
|
||
/// 埋点
|
||
/// name:事件名
|
||
/// parameters:业务参数
|
||
static void logEvent(String eventName, {Map<String, Object>? parameters}) {
|
||
try {
|
||
FirebaseAnalytics.instance.logEvent(
|
||
name: eventName,
|
||
parameters: parameters,
|
||
);
|
||
} catch (e) {
|
||
LogUtil.e(e.toString());
|
||
}
|
||
}
|
||
|
||
/// 启动页曝光
|
||
static void logLaunchPV() {
|
||
logEvent('launch_pv');
|
||
}
|
||
|
||
/// 跳转
|
||
static void logJumpEvent(String? side, String? reason) {
|
||
logEvent('jump_event',
|
||
parameters: {
|
||
'side': ObjUtil.getStr(side),
|
||
'reason': ObjUtil.getStr(reason)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// A面首页曝光
|
||
static void logHomeAPV() {
|
||
logEvent('home_a_pv');
|
||
}
|
||
|
||
/// B面首页曝光
|
||
static void logHomeBPV() {
|
||
logEvent('home_b_pv');
|
||
}
|
||
|
||
/// 首页资源曝光成功
|
||
static void logHomeBModuleShowsuccesAction() {
|
||
logEvent('home_b_module_showsucces_action');
|
||
}
|
||
|
||
/// 首页资源曝光失败
|
||
static void logHomeBModuleFailAction(String? failreason) {
|
||
logEvent('home_b_module_fail_action',
|
||
parameters: {
|
||
'failreason': ObjUtil.getStr(failreason)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 点击首页模块
|
||
static void logHomeBModuleClick(String? modulename) {
|
||
logEvent('home_b_module_click',
|
||
parameters: {
|
||
'modulename': ObjUtil.getStr(modulename)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// B面我的曝光
|
||
static void logMeBPV() {
|
||
logEvent('me_b_pv');
|
||
}
|
||
|
||
/// 点击歌曲
|
||
static void logSongClick(String? songfrom) {
|
||
logEvent('song_click',
|
||
parameters: {
|
||
'songfrom': ObjUtil.getStr(songfrom)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// B面歌曲曝光
|
||
static void logPlayerBpv(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_pv',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 统计加载时间
|
||
static void logPlayerBDelayAction(String? videoid, String? videoname, String? artistname, String? delay) {
|
||
logEvent('player_b_delay_action',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
'delay': ObjUtil.getStr(delay),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 播放成功
|
||
static void logPlayerBSuccessAction(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_success_action',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 播放失败
|
||
static void logPlayerBFailAction(String? failreason) {
|
||
logEvent('player_b_fail_action',
|
||
parameters: {
|
||
'failreason': ObjUtil.getStr(failreason)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 收藏
|
||
static void logPlayerBLoveClick(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_love_click',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 取消收藏
|
||
static void logPlayerBUnloveClick(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_unlove_click',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 点击下载
|
||
static void logPlayerBDownloadClick(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_download_click',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 下载成功
|
||
static void logPlayerBDownloadsuccessAction(String? videoid, String? videoname, String? artistname) {
|
||
logEvent('player_b_downloadsuccess_action',
|
||
parameters: {
|
||
'videoid': ObjUtil.getStr(videoid),
|
||
'videoname': ObjUtil.getStr(videoname),
|
||
'artistname': ObjUtil.getStr(artistname),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 下载失败
|
||
static void logPlayerBDownloadfailAction(String? failreason) {
|
||
logEvent('player_b_downloadfail_action',
|
||
parameters: {
|
||
'failreason': ObjUtil.getStr(failreason)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// B面搜索曝光
|
||
static void logSearchPV() {
|
||
logEvent('search_pv');
|
||
}
|
||
|
||
/// 搜索SUG曝光
|
||
static void logSearchSugShow() {
|
||
logEvent('search_sug_show');
|
||
}
|
||
|
||
/// 输入搜索内容,点击搜索(包含联想点击)
|
||
static void logSearchSugClick(String? sugname) {
|
||
logEvent('search_sug_click',
|
||
parameters: {
|
||
'sugname': ObjUtil.getStr(sugname)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 搜索结果曝光
|
||
static void logSearchResultPV() {
|
||
logEvent('search_result_pv');
|
||
}
|
||
|
||
/// 搜索有结果
|
||
static void logSearchResultsuccessAction() {
|
||
logEvent('search_resultsuccess_action');
|
||
}
|
||
|
||
/// 搜索无结果
|
||
static void logSearchResultfailAction(String? failreason) {
|
||
logEvent('search_resultfail_action',
|
||
parameters: {
|
||
'failreason': ObjUtil.getStr(failreason)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 搜索点击
|
||
static void logSearchFromAction(String? searchfrom) {
|
||
logEvent('search_from_action',
|
||
parameters: {
|
||
'searchfrom': ObjUtil.getStr(searchfrom)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 播放器弹出
|
||
static void logPlayerBImp() {
|
||
logEvent('player_b_imp');
|
||
}
|
||
|
||
/// 列表加载
|
||
static void logPlayerBList() {
|
||
logEvent('player_b_list');
|
||
}
|
||
|
||
/// 创建歌单
|
||
static void logCreateList() {
|
||
logEvent('create_list');
|
||
}
|
||
|
||
/// 曲库点击
|
||
static void logLibraryClick(String? clickfrom, String? folderclick) {
|
||
logEvent('library_click',
|
||
parameters: {
|
||
'clickfrom': ObjUtil.getStr(clickfrom),
|
||
'folderclick': ObjUtil.getStr(folderclick)
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 广告展示机会
|
||
static void logPlayAdsChanceAction() {
|
||
logEvent('play_ads_chance');
|
||
}
|
||
|
||
/// 广告加载失败
|
||
static void logPlayAdsLoadFailure(String? error) {
|
||
logEvent('play_ads_loadFailure',
|
||
parameters: {
|
||
'error': ObjUtil.getStr(error),
|
||
},
|
||
);
|
||
}
|
||
|
||
/// 广告展示成功
|
||
static void logPlayAdsShowSuccess(Ad ad) {
|
||
var mediation = '';
|
||
if (ad.responseInfo != null && ad.responseInfo!.responseExtras.isNotEmpty) {
|
||
mediation = ad.responseInfo!.responseExtras['mediation_group_name'];
|
||
}
|
||
logEvent('play_ads_showSuccess',
|
||
parameters: {
|
||
'platform': ObjUtil.getStr(ad.responseInfo?.loadedAdapterResponseInfo?.adSourceName),
|
||
'source': ObjUtil.getStr(ad.responseInfo?.loadedAdapterResponseInfo?.adSourceInstanceName),
|
||
'unitName': ObjUtil.getStr(mediation),
|
||
},
|
||
);
|
||
|
||
}
|
||
|
||
/// 广告展示失败
|
||
static void logPlayAdsShowFailure(String? error) {
|
||
logEvent('play_ads_showFailure',
|
||
parameters: {
|
||
'error': ObjUtil.getStr(error),
|
||
},
|
||
);
|
||
}
|
||
}
|