什么是电子商务网站建设与管理,app开发公司认可湖南岚鸿推 荐,电影网站logo设计,长沙教育网站开发一、说明
电商网站中已经有越来越多的用户来自移动端#xff0c;相比起传统浏览器的登录方式#xff0c;手机APP成为了更多用户访问电商网站的首选。对于电商企业来说#xff0c;一般会通过各种不同的渠道对自己的APP进行市场推广#xff0c;而这些渠道的统计数据#xf…一、说明
电商网站中已经有越来越多的用户来自移动端相比起传统浏览器的登录方式手机APP成为了更多用户访问电商网站的首选。对于电商企业来说一般会通过各种不同的渠道对自己的APP进行市场推广而这些渠道的统计数据比如不同网站上广告链接的点击量、APP下载量就成了市场营销的重要商业指标。
二、思路
统计 不同渠道的不同用户行为
三、数据准备
封装数据的JavaBean类
package com.lyh.flink06;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;Data
AllArgsConstructor
NoArgsConstructor
public class MarketingUserBehavior {private Long userId;private String behavior;private String channel;private Long timestamp;
}四、代码
package com.lyh.flink06;import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.source.SourceFunction;import java.util.Random;public class Project_AppAnalysis_By_Chanel {public static void main(String[] args) throws Exception {StreamExecutionEnvironment env StreamExecutionEnvironment.getExecutionEnvironment();env.setParallelism(2);env.addSource(new AppSource()).map(new MapFunctionMarketingUserBehavior, Tuple2String,Long() {Overridepublic Tuple2String, Long map(MarketingUserBehavior value) throws Exception {return Tuple2.of(value.getBehavior() _ value.getChannel(),1L);}}).keyBy(0).sum(1).print();env.execute();}public static class AppSource implements SourceFunctionMarketingUserBehavior {Overridepublic void run(SourceContextMarketingUserBehavior ctx) throws Exception {Random random new Random();String[] behaviors {update, install, uninstall, update};String[] chanels {HW,VIVO,XIAOMI,OPPO};while (true){Long userId (long)(random.nextInt(2000) 1);String behavior behaviors[random.nextInt(behaviors.length)];String chanel chanels[random.nextInt(chanels.length)];Long timstampes System.currentTimeMillis();ctx.collect(new MarketingUserBehavior(userId,behavior,chanel,timstampes));Thread.sleep(200);}}Overridepublic void cancel() {}}}五、运行结果