失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > php mysql计算留存率_用户留存率算法

php mysql计算留存率_用户留存率算法

时间:2023-12-22 17:35:47

相关推荐

php mysql计算留存率_用户留存率算法

玩家在某段时间内注册开始游戏,经过一段时间后,仍然继续游戏的被认作是留存;这部分用户占当时新增用户的比例即是留存率,会按照每隔1单位时间(例日、周、月)来进行统计。顾名思义,留存指的就是“有多少玩家留下来了”。留存用户和留存率体现了应用的质量和保留用户的能力。

次日留存率

首次登陆后第二天登录游戏用户/统计日的注册用户数

三日留存率

首次登陆后第三天登陆过的用户/统计日的注册用户数

七日留存率

首次登陆后第七天登录过游戏的用户/统计日的注册用户数

三十日留存数

首次登陆后第三十天登录过游戏的用户/统计日的注册用户数

留存率在不同的游戏中算法不一样

留存率说明

某时间内的新增用户,经过一段时间后,仍继续登录游戏的被认作时留存用户;这部分用户占当时新增用户的比例即是留存率。

例如:

9月5日新增用户200,这200人在6日登录游戏的有100人,7日登录有80人,8日登录有50人;

则9月5日次日留存率是50%,3日留存率是40%,4日留存率是25%。

这是我们游戏里的计算方式

这样统计有科学根据的

比如哪天你开广告了就可以看他带来的用户质量

还有这样的留存数据也会好看的

--登录日志

DROPTABLEIFEXISTSlog_login;

CREATETABLElog_login(

idINT(11)UNSIGNEDNOTNULLAUTO_INCREMENT,

player_idINT(11)UNSIGNEDNOTNULL,

last_login_timetimestampNOTNULLDEFAULT'2000-01-0100:00:00',

register_timetimestampNOTNULLDEFAULT'2000-01-0100:00:00',

PRIMARYKEY(id)

)ENGINE=MYISAMDEFAULTCHARSET=utf8;

log_login的数据在每个玩家登陆的时候产生一条,为了接下去的存储过程执行效率的考虑,冗余了每个玩家的注册时间。

--统计留存率

DROPTABLEIFEXISTSstat_remain;

CREATETABLEstat_remain(

idINT(11)UNSIGNEDNOTNULLAUTO_INCREMENT,

druINT(11)NOTNULL,--每日新注册用户

second_dayINT(11)DEFAULTNULL,

third_dayINT(11)DEFAULTNULL,

seventh_dayINT(11)DEFAULTNULL,

thirtieth_dayINT(11)DEFAULTNULL,

stat_timetimestampNOTNULLDEFAULT'2000-01-0100:00:00',

add_timetimestampNOTNULLDEFAULT'2000-01-0100:00:00',

PRIMARYKEY(id)

)ENGINE=MYISAMDEFAULTCHARSET=utf8;

DELIMITER$$

--统计留存率

DROPPROCEDUREIFEXISTSstat_remain_player$$

CREATEPROCEDUREstat_remain_player()

BEGIN

declareiint;

SETi=1;

insertintostat_remain(dru,stat_time,add_time)selectcount(a_qid),date_sub(curdate(),interval1day),now()fromtb_fishwheredatediff(now(),add_time)=1;

whilei<30do

if(i=1)or(i=2)or(i=6)or(i=29)then

ifexists(select*fromstat_remainwheredatediff(curdate(),stat_time)=i)then

updatestat_remainsetsecond_day=(select(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=ianddatediff(date_add(curdate(),interval1-iday),last_login_time)=0)/(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=i))*100wheredatediff(curdate(),stat_time)=i;

updatestat_remainsetthird_day=(select(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=ianddatediff(date_add(curdate(),interval2-iday),last_login_time)=0)/(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=i))*100wheredatediff(curdate(),stat_time)=i;

updatestat_remainsetseventh_day=(select(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=ianddatediff(date_add(curdate(),interval6-iday),last_login_time)=0)/(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=i))*100wheredatediff(curdate(),stat_time)=i;

updatestat_remainsetthirtieth_day=(select(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=ianddatediff(date_add(curdate(),interval29-iday),last_login_time)=0)/(selectcount(distinctplayer_id)fromlog_loginwheredatediff(curdate(),register_time)=i))*100wheredatediff(curdate(),stat_time)=i;

endif;

endif;

SETi=i+1;

endwhile;

END

$$

DELIMITER;

stat_remain_player 存储过程在每新的一天的0点0分1秒左右去执行,生成stat_remain数据,并对离当天stat_time差距为1天,2天,6天和29天的记录进行更新

如果觉得《php mysql计算留存率_用户留存率算法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。