游戏玩家的留存率统计实现

简介: 游戏玩家的留存率统计实现

 

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

 

 

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

 

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

留存率说明

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

例如:

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

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

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

这样统计 有科学根据的

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

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

 

 

 

 

-- 登录日志
DROP TABLE IF EXISTS log_login;
CREATE TABLE log_login(
  id INT (11) UNSIGNED NOT NULL AUTO_INCREMENT,
  player_id INT(11) UNSIGNED NOT NULL,
  last_login_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',
  register_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00', 
  PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=utf8;

 

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

 

-- 统计留存率
DROP TABLE IF EXISTS stat_remain;
CREATE TABLE stat_remain(
  id INT (11) UNSIGNED NOT NULL AUTO_INCREMENT,
  dru INT(11) NOT NULL, -- 每日新注册用户
  second_day INT(11) DEFAULT NULL,
  third_day INT(11) DEFAULT NULL,
  seventh_day INT(11) DEFAULT NULL,
  thirtieth_day INT(11) DEFAULT NULL,  
  stat_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',
  add_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00', 
  PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=utf8;

 

DELIMITER $$

-- 统计留存率

DROP PROCEDURE IF EXISTS stat_remain_player$$

CREATE PROCEDURE stat_remain_player()

BEGIN

-- 今天的日期

declare today date default curdate();

declare yesterday date default date_sub(today, interval 1 day);

declare days_ago_2 date default date_sub(today, interval 2 day);

declare days_ago_3 date default date_sub(today, interval 3 day);

declare days_ago_4 date default date_sub(today, interval 4 day);



declare days_ago_6 date default date_sub(today, interval 6 day);

declare days_ago_7 date default date_sub(today, interval 7 day);



declare days_ago_13 date default date_sub(today, interval 13 day);

declare days_ago_14 date default date_sub(today, interval 14 day);



declare days_ago_29 date default date_sub(today, interval 29 day);

declare days_ago_30 date default date_sub(today, interval 30 day);



-- 统计昨天DRU(就是昨天一天的注册人数)

insert into stat_remain(dru, stat_time, add_time) select count(id) , yesterday, now() from user where role_num>0 and roll=false and last_login_time>'2000-01-01' and add_time between yesterday and today;



-- 修改前天的2日留存

update stat_remain set second_day = (
select(
   (select count(distinct player_id) from log_login where (register_time between days_ago_2 and yesterday) and (last_login_time between yesterday and today))
/ 
(select count(distinct player_id) from log_login where (register_time between days_ago_2 and yesterday))
)
) where stat_time = days_ago_2;



-- 修改大前天的3日留存

update stat_remain set third_day = (
select(
   (select count(distinct player_id) from log_login where (register_time between days_ago_3 and days_ago_2) and (last_login_time between yesterday and today))
/ 
(select count(distinct player_id) from log_login where (register_time between days_ago_3 and days_ago_2))
)
) where stat_time = days_ago_3;


-- 7日留存

update stat_remain set seventh_day = (
select(
   (select count(distinct player_id) from log_login where (register_time between days_ago_7 and days_ago_6) and (last_login_time between yesterday and today))
/ 
(select count(distinct player_id) from log_login where (register_time between days_ago_7 and days_ago_6))
)
) where stat_time = days_ago_7;



-- 14日留存

update stat_remain set fourteen_day = (
select(
   (select count(distinct player_id) from log_login where (register_time between days_ago_14 and days_ago_13) and (last_login_time between yesterday and today))
/ 
(select count(distinct player_id) from log_login where (register_time between days_ago_14 and days_ago_13))
)
) where stat_time = days_ago_14;



-- 30日留存

update stat_remain set thirtieth_day = (
select(
   (select count(distinct player_id) from log_login where (register_time between days_ago_30 and days_ago_29) and (last_login_time between yesterday and today))
/ 
(select count(distinct player_id) from log_login where (register_time between days_ago_30 and days_ago_29))
)
) where stat_time = days_ago_30;
END
$$



DELIMITER ;

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

 

目录
相关文章
|
存储 前端开发 JavaScript
第六章(原理篇) 微前端间的通信机制
第六章(原理篇) 微前端间的通信机制
558 0
|
3月前
|
人工智能 算法 搜索推荐
2025年国内数字人平台选购指南:聚焦全链路能力,告别工具碎片化困境
国内数字人平台众多,功能参差,用户常陷多工具切换、成本高、效率低困境。本文基于2025年实测数据,从全链路集成、场景适配、技术壁垒、成本效益四大维度,深度解析必火AI、火山、阿里、讯飞等主流平台,助你避开选择陷阱,精准匹配个人IP、电商直播、企业服务等应用场景,实现高效视频化转型。
|
5月前
|
机器学习/深度学习 边缘计算 算法
SEENN: 迈向时间脉冲早退神经网络——论文阅读
SEENN提出一种时间脉冲早退神经网络,通过自适应调整每个样本的推理时间步数,有效平衡脉冲神经网络的准确率与计算效率。该方法基于置信度判断或强化学习策略,在保证高精度的同时显著降低能耗与延迟,适用于边缘计算与实时处理场景。
333 13
|
数据采集 测试技术
Selenium与WebDriver:Errno 8 Exec格式错误的多种解决方案
本文讨论了在使用Selenium和WebDriver自动化测试时常见的执行格式错误(Errno 8 Exec format error)问题。错误通常发生在运行ChromeDriver时,与兼容性或路径配置有关。文章提供了多种解决方案,包括手动更改路径、更新或重新安装webdriver-manager包、下载特定版本的ChromeDriver、修改driver_cache.py文件。此外,还介绍了如何结合代理IP技术使用Selenium进行网页抓取,以提高效率和成功率。示例代码展示了如何配置代理IP并使用Selenium访问网站。通过这些方法,用户可以有效解决执行格式错误,并提高网页自动化测试
1399 1
Selenium与WebDriver:Errno 8 Exec格式错误的多种解决方案
|
JavaScript 前端开发 API
Next.js 实战 (六):如何实现文件本地上传
这篇文章介绍了在Next.js中如何实现文件上传到本地的方法。文章首先提到Next.js官方文档中没有提供文件上传的实例代码,因此开发者需要自行实现,通常有两种思路:使用Node.js原生上传或使用第三方插件如multer。接着,文章选择了使用Node.js原生上传的方式来讲解实现过程,包括如何通过哈希值命名文件、上传到指定目录以及如何分类文件夹。然后,文章展示了具体的实现步骤,包括编写代码来处理文件上传,并给出了代码示例。最后,文章通过一个效果演示说明了如何通过postman模拟上传文件,并展示了上传后的文件夹结构。
429 0
Next.js 实战 (六):如何实现文件本地上传
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
存储 JSON NoSQL
【文档数据库】ES和MongoDB的对比
【文档数据库】ES和MongoDB的对比
1215 1
|
安全 网络安全 数据安全/隐私保护
CTF竞赛:一场网络安全技术的盛宴
CTF竞赛:一场网络安全技术的盛宴
632 0
|
机器学习/深度学习 JavaScript 前端开发
2023最新之 教你如何使用Springboot集成支付宝沙箱支付(支持回调- 亲测有效)
2023最新之 教你如何使用Springboot集成支付宝沙箱支付
1557 0
|
SQL 前端开发 Java
若依框架---PageHelper分页(一)
若依框架---PageHelper分页(一)
2239 0

热门文章

最新文章