/**
* 神策数据统计 所有事件方法工具类
*/
public class SensersAnalyticsUntil {
/**
* 添加事件公共属性
*/
public static void addEventCommonAttribute(Context context) {
try {
JSONObject properties = new JSONObject();
properties.put("PlatformType", "Android");
properties.put("appName", context.getString(R.string.app_name));
SensorsDataAPI.sharedInstance(context).registerSuperProperties(properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App激活事件 英文变量 : AppInstall
* 第一次安装App的第一次启动事件,并且包含了渠道广告信息
*/
public static void addActivation(Context context) {
try {
JSONObject properties = new JSONObject();
String utmSource = null;
// String utmCampaign = null;
// 获取 中的 必需已经配置
// 获取渠道名称 (utm_source)
utmSource = SensorsDataUtils.getApplicationMetaData(context, "SENSORS_ANALYTICS_UTM_SOURCE");
// 获取广告名称 (utm_campaign)
// utmCampaign = SensorsDataUtils.getApplicationMetaData(context, "SENSORS_ANALYTICS_UTM_CAMPAIGN");
// 设置渠道名称属性
properties.put("$utm_source", utmSource);
// 设置广告名称属性
// properties.put("$utm_campaign", utmCampaign);
// 记录激活事件,追踪渠道效果
SensorsDataAPI.sharedInstance(context).trackInstallation("AppInstall", properties);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* App页面浏览事件开始 英文变量 : $AppViewScreen
*/
public static void startPageViews(Context context) {
// 调用 trackTimerBegin("事件名") 标记事件启动时间
SensorsDataAPI.sharedInstance(context).trackTimerBegin("$AppViewScreen");
}
/**
* App页面浏览事件结束 英文变量 : $AppViewScreen
*/
public static void endPageViews(Context context, String title, String activity_name) {
try {
JSONObject properties = new JSONObject();
properties.put("$title", title); //设置 Activity标题
properties.put("$screen_name", "cn.com.jmw.m.activity." + activity_name); //设置 页面名称 完整包名+类名
// 调用 track,记录 eventName 事件,并在属性 event_duration 中记录浏览的时间
SensorsDataAPI.sharedInstance(context).trackTimerEnd("$AppViewScreen", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App页面浏览事件 英文变量 : $AppViewScreen
*/
public static void addPageViews(Context context, String title, String activity_name) {
try {
JSONObject properties = new JSONObject();
properties.put("$title", title); //设置 Activity标题
properties.put("$screen_name", "cn.com.jmw.m.activity." + activity_name); //设置 页面名称 完整包名+类名
SensorsDataAPI.sharedInstance(context).trackViewScreen(null, properties);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* App页面浏览事件 英文变量 : $AppViewScreen
*/
public static void addFragmentPageViews(Context context, String title, String fragment_name) {
try {
JSONObject properties = new JSONObject();
properties.put("$title", title); //设置 Activity标题
properties.put("$screen_name", "cn.com.jmw.m.fragment." + fragment_name); //设置 页面名称 完整包名+类名
SensorsDataAPI.sharedInstance(context).trackViewScreen(null, properties);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* App用户登录事件 英文变量 : login
*/
public static void addLogin(Context context, String from_page, String user_phone) {
// SensorsDataAPI.sharedInstance(context).login(user_id); 调用神策的用户登录与本公司的用户相关联
try {
JSONObject properties = new JSONObject();
properties.put("location", from_page); // 设置 所在页面
//location 取值参考 : Activity在AndroidManifest中的label值
properties.put("login_number", user_phone); // 设置 手机号码
SensorsDataAPI.sharedInstance(context).track("login", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App用户注销 该事件不进行统计 在用户注销及登录过期时调用
*/
public static void addLoginout(Context context) {
// 用户退出清空 注册ID
SensorsDataAPI.sharedInstance(context).logout();
}
/**
* App搜索单页搜索事件 英文变量 : search
*/
public static void addSearch(Context context, String key_word, String isRecommend) {
try {
JSONObject properties = new JSONObject();
properties.put("keyWord", key_word); // 设置 搜索关键词
properties.put("isRecommend", isRecommend); // 设置 是否使用热门搜索
//isRecommend 取值参考 : 是,否
SensorsDataAPI.sharedInstance(context).track("search", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App底部类别点击 英文变量 : tab_click
*/
public static void addMainBottomTabClick(Context context, String tab_name) {
try {
JSONObject properties = new JSONObject();
properties.put("tab_name", tab_name); // 设置 tab名称
//tab_name 取值参考 : 首页,分类,发现,我的
SensorsDataAPI.sharedInstance(context).track("tab_click", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App首页轮播图点击 英文变量 : banner
*/
public static void addHomeBannerClick(Context context, String banner_id) {
try {
JSONObject properties = new JSONObject();
properties.put("banner_id", banner_id); // 设置 轮播图项目id
SensorsDataAPI.sharedInstance(context).track("banner", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App首页导航模块点击 英文变量 : model_Click
*/
public static void addHomeIndustryNavigationClick(Context context, String model_name) {
try {
JSONObject properties = new JSONObject();
properties.put("model_name", model_name); // 设置 导航栏行业名称
SensorsDataAPI.sharedInstance(context).track("model_Click", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App搜索栏点击 英文变量 : search_bar
*/
public static void addSearchBarClick(Context context, String searchbar_name) {
try {
JSONObject properties = new JSONObject();
properties.put("searchbar_name", searchbar_name); // 设置 所在页面名称
//searchbar_name 取值参考 : 首页固定,首页跟随,分类,发现,文章页,标页
SensorsDataAPI.sharedInstance(context).track("search_bar", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App首页品牌专区模块点击 英文变量 : brand_zone
*/
public static void addHomeBrandAreaClick(Context context, String brand_name) {
try {
JSONObject properties = new JSONObject();
properties.put("brand_name", brand_name); // 设置 内容名称
//brand_name 取值参考 : 品牌专区名(1831专区,大众美食专区,品牌核实专区)
SensorsDataAPI.sharedInstance(context).track("brand_zone", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App加盟聚焦 英文变量 : join_focus
*/
public static void addHomeJoinFocusClick(Context context, String join_name, String join_site) {
try {
JSONObject properties = new JSONObject();
properties.put("join_name", join_name); // 设置 加盟聚焦项目名
properties.put("join_site", join_site); // 设置 加盟聚焦项目位置 从1开始
SensorsDataAPI.sharedInstance(context).track("join_focus", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App首页我要加盟/我要招商点击 英文变量 : Invest
*/
public static void addHomeInvestClick(Context context, String invest_type) {
try {
JSONObject properties = new JSONObject();
properties.put("invest_type", invest_type); // 设置 类型
//invest_type 取值参考 : 定制推荐,企业入驻
SensorsDataAPI.sharedInstance(context).track("Invest", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App分类页模型点击 英文变量 : Classify
*/
public static void addClassifyClick(Context context, String classify_modelname, String classify_contentname) {
try {
JSONObject properties = new JSONObject();
properties.put("classify_modelname", classify_modelname); // 设置 模块名称
//classify_modelname 取值参考 : 顶部四格,6宫格,加盟说,餐饮,教育,汽车,查看所有分类
properties.put("classify_contentname", classify_contentname); // 设置 内容名称
//classify_contentname 取值参考 : 顶部四格(专人审核,12万项目,加盟管家,1831认证)
// 6个活动专区(机器人教育,大众美食,超级品牌,品牌核实,良选,鱼火锅)
// 加盟说,餐饮(查看更多箭头:餐饮查看更多),教育(查看更多箭头:教育查看更多),汽车(查看更多箭头:汽车查看更多)
SensorsDataAPI.sharedInstance(context).track("Classify", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App发现页模型点击 英文变量 : Find
*/
public static void addFindClick(Context context, String find_modelname) {
try {
JSONObject properties = new JSONObject();
properties.put("find_modelname", find_modelname); // 设置 模块
//find_modelname 取值参考 :1831专区与品牌核实,热门行业(特色美食,幼儿教育,潮流饮品,机器人智能,酒店民宿,教育辅导)
SensorsDataAPI.sharedInstance(context).track("Find", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App发现页项目点击 英文变量 : Find_brand
*/
public static void addFindProjectClick(Context context, String find_modelname, String find_brandsite) {
try {
JSONObject properties = new JSONObject();
properties.put("find_brandname", find_modelname); // 设置 品牌名称
properties.put("find_brandsite", find_brandsite); // 设置 品牌位置 从1开始
SensorsDataAPI.sharedInstance(context).track("Find_brand", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App标页入口点击 英文变量 : Detail_page
*/
public static void addProjectPageClick(Context context, String detail_enter, String detail_name, String detail_money, String indudtry_id, String indudtry_child_id, String detail_itemid) {
try {
JSONObject properties = new JSONObject();
properties.put("detail_enter", detail_enter); // 设置 入口
//detail_enter 取值参考 :首页,分类,发现,我的,猜你喜欢,1831专区
properties.put("detail_name", detail_name); // 设置 加盟店名称
//detail_name 取值参考 :柠檬工坊,阿香米线,无印良品
properties.put("detail_money", detail_money); // 设置 投资金额
//detail_money 取值参考 :10-50
properties.put("detail_indudtryid", indudtry_id); // 设置 一级行业ID
properties.put("detail_subindudtryid", indudtry_child_id); // 设置 二级行业ID
properties.put("detail_itemid", detail_itemid); // 设置 项目ID
SensorsDataAPI.sharedInstance(context).track("Detail_page", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App标页按钮点击 英文变量 : Detail_button
*/
public static void addStandardButton(Context context, String analyse_name, String analyse_button) {
try {
JSONObject properties = new JSONObject();
properties.put("detail_name", analyse_name); // 设置 加盟店名称
//detail_name 取值参考 :柠檬工坊,阿香米线,无印良品
properties.put("analyse_button", analyse_button); // 设置 按钮名称
//analyse_button 取值参考 :1.立即咨询按钮2.获取开店方案按钮3.在线咨询按钮
SensorsDataAPI.sharedInstance(context).track("Detail_button", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* App提交留言事件 英文变量 : Message
*/
public static void addMessage(Context context, String message_enter, String message_id, String message_number) {
try {
JSONObject properties = new JSONObject();
properties.put("message_enter", message_enter); // 设置 入口
//message_enter 取值参考 : 首页-我要招商,标页-立即咨询,标页-获取开店方案,标页-在线留言,标页-咨询她
properties.put("message_id", message_id); // 设置 加盟店id
properties.put("message_number", message_number); // 设置 手机号码
SensorsDataAPI.sharedInstance(context).track("Message", properties);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
这样神策埋点就完成了 是不是特别简单