用戶留存率算法


玩家在某段時間內注冊開始游戲,經過一段時間后,仍然繼續游戲的被認作是留存;這部分用戶占當時新增用戶的比例即是留存率,會按照每隔1單位時間(例日、周、月)來進行統計。顧名思義,留存指的就是“有多少玩家留下來了”。留存用戶和留存率體現了應用的質量和保留用戶的能力。
次日留存率 首次登陸后第二天登錄游戲用戶/統計日的注冊用戶數
三日留存率 首次登陸后第三天登陸過的用戶/統計日的注冊用戶數
七日留存率 首次登陸后第七天登錄過游戲的用戶/統計日的注冊用戶數
三十日留存數 首次登陸后第三十天登錄過游戲的用戶/統計日的注冊用戶數
留存率 在不同的游戲中 算法不一樣
留存率說明
某時間內的新增用戶,經過一段時間后,仍繼續登錄游戲的被認作時留存用戶;這部分用戶占當時新增用戶的比例即是留存率。
例如:
9月5日新增用戶200,這200人在6日登錄游戲的有100人,7日登錄有80人,8日登錄有50人;
則9月5日次日留存率是50%,3日留存率是40%,4日留存率是25%。
這是我們游戲里的計算方式
 這樣統計 有科學根據的
比如 哪天 你開廣告了 就可以看 他帶來的用戶質量
還有 這樣的留存 數據 也會好看的

 

 

 

  1. -- 登錄日志  
  2. DROP TABLE IF EXISTS log_login;  
  3. CREATE TABLE log_login(  
  4.   id INT (11) UNSIGNED NOT NULL AUTO_INCREMENT,  
  5.   player_id INT(11) UNSIGNED NOT NULL,  
  6.   last_login_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',  
  7.   register_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',   
  8.   PRIMARY KEY (id)  
  9. )ENGINE=MYISAM DEFAULT CHARSET=utf8;  

 

log_login的數據在每個玩家登陸的時候產生一條,為了接下去的存儲過程執行效率的考慮,冗余了每個玩家的注冊時間。

 

  1. -- 統計留存率  
  2. DROP TABLE IF EXISTS stat_remain;  
  3. CREATE TABLE stat_remain(  
  4.   id INT (11) UNSIGNED NOT NULL AUTO_INCREMENT,  
  5.   dru INT(11) NOT NULL-- 每日新注冊用戶  
  6.   second_day INT(11) DEFAULT NULL,  
  7.   third_day INT(11) DEFAULT NULL,  
  8.   seventh_day INT(11) DEFAULT NULL,  
  9.   thirtieth_day INT(11) DEFAULT NULL,    
  10.   stat_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',  
  11.   add_time timestamp NOT NULL DEFAULT '2000-01-01 00:00:00',   
  12.   PRIMARY KEY (id)  
  13. )ENGINE=MYISAM DEFAULT CHARSET=utf8;  

 

  1. DELIMITER $$  
  2. -- 統計留存率  
  3. DROP PROCEDURE IF EXISTS stat_remain_player$$  
  4. CREATE PROCEDURE stat_remain_player()  
  5. BEGIN  
  6. declare i int;  
  7. SET i = 1;    
  8.   
  9. insert into stat_remain(dru,stat_time,add_time) select count(a_qid),date_sub(curdate(),interval 1 day),now() from tb_fish where datediff(now(),add_time)=1;  
  10.   
  11.   
  12. while i<30 do   
  13.  if (i=1) or (i=2) or (i=6) or (i=29) then  
  14.     if exists(select * from stat_remain where datediff(curdate(),stat_time) =i) then                                                                 
  15.     update stat_remain set second_day=(select (select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i and datediff(date_add(curdate(),interval 1-i day),last_login_time)=0)/(select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i))*100 where datediff(curdate(),stat_time) =i;    
  16.     update stat_remain set third_day=(select (select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i and datediff(date_add(curdate(),interval 2-i day),last_login_time)=0)/(select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i))*100 where datediff(curdate(),stat_time) =i;    
  17.     update stat_remain set seventh_day=(select (select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i and datediff(date_add(curdate(),interval 6-i day),last_login_time)=0)/(select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i))*100 where datediff(curdate(),stat_time) =i;    
  18.     update stat_remain set thirtieth_day=(select (select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i and datediff(date_add(curdate(),interval 29-i day),last_login_time)=0)/(select count(distinct player_id) from log_login where datediff(curdate(),register_time) =i))*100 where datediff(curdate(),stat_time) =i;    
  19.     end if;  
  20. end if;  
  21. SET i = i + 1;    
  22. end while;    
  23. END  
  24. $$  
  25.   
  26. DELIMITER ;  

 

stat_remain_player 存儲過程在每新的一天的0點0分1秒左右去執行,生成stat_remain數據,並對離當天stat_time差距為1天,2天,6天和29天的記錄進行更新


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM