In the spirit of "gamification"
Thinking back to my history in gaming, I came up with a script that lets you track how many consecutive days a user has logged in.
Basically this means that you can reward users (with a badge, rank?) for logging in every day.
Maybe someone finds it useful.
I use three variables, date,a,b. String example: 2014-07-10,1,5.
Where date is last date the user logged in.
a Is the running total of consecutive logins. If a user skips a day of logging, this resets to zero.
b Is the max number of consecutive days the user has managed to reach so far.
Here's what the script does:
Read string from a custom profile field, field1.
Check last login date (set today if this is the first login (since adding the script, or ever).
If user logged in yesterday as well, increase a by 1.
Check if a is greater than b. If so, increase b by 1.
<!-- Consecutive logins --> <#if user.registered> <#assign UserDateLast = restadmin("/users/id/${user.id}/profiles/name/field1").value /> <script type="text/javascript"> var vToday = new Date();var dd = vToday.getDate();var mm = vToday.getMonth()+1;var yyyy = vToday.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} vToday = yyyy+'-'+mm+'-'+dd; var vLastLoginDate = '${UserDateLast}'; var arLastLoginDate = new Array(); if (vLastLoginDate == '') { arLastLoginDate[0] = vToday; arLastLoginDate[1] = 0; arLastLoginDate[2] = 1; } else { arLastLoginDate = vLastLoginDate.split(","); } var firstDate = new Date(arLastLoginDate[0]); var secondDate = new Date(vToday); var diffDays = (secondDate - firstDate) / (24 * 60 * 60 * 1000); if (diffDays > 1) { arLastLoginDate[1] = 0; } if (diffDays == 1) { arLastLoginDate[1] = Number(arLastLoginDate[1]) + 1; } if (Number(arLastLoginDate[1]) > Number(arLastLoginDate[2])) { arLastLoginDate[2] = Number(arLastLoginDate[2]) + 1; } arLastLoginDate[0] = vToday; $.post('/restapi/vc/users/id/${user.id}/profiles/name/field1/set', {value: '' + arLastLoginDate}); </script> </#if>