# đź”Ą User Streaks (Gamification)

Hi Gliders!

Just thought Iâ€™d share a quick video showing one of many ways you can introduce â€śuser streaksâ€ť into your app. For example, you could use this in a Workout app where you reward members for logging workouts on a daily basis.

Iâ€™m sure there are better/more resource efficient ways of getting this done (Iâ€™ve already spotted ways to improve my own solution ) but a Loqode student asked how it could be done in our Q&A this morning so I thought Iâ€™d post the solution I came up with here as well.

If you have any questions, want the Google Script code, or have suggestions on how this can be improved Iâ€™d love to hear from you!

Enjoy

3 Likes

Creative, nicely done

I think the only thing I would do differently would be to use JavaScript to calculate the streak, rather than calling an external script. Iâ€™d also pass the dates as integers - just makes them easier to work with as you can do direct numerical comparisons. Another option would be to transpose the list of dates into a Helper Table, and then figure it out from there. But thatâ€™s probably a bit of overkill, and youâ€™d need enough rows in the table to cover the maximum streak length. So not really a good option.

Side note: I suspect the reason why you couldnâ€™t use greater than/less than with the streak count is probably because your script returns the number as a string. If you run that through a Math column (multiply by 1) that should coerce it into a number.

3 Likes

Thanks Darren!

During the live Q&A itself I attempted to use the Javascript column but didnâ€™t spend enough time tweaking to get it up & runningâ€¦ Then for some reason after the session I decided to try using a script and it worked so I kinda just rolled with it

But I agree, using the Javascript column would be a neater solution. Besides the fact that you wonâ€™t have to rely on external scripts, what are the benefits of doing it â€śin houseâ€ť? Iâ€™ve always assumed itâ€™s better but only from a â€śless breakable partsâ€ť and faster response time point of viewâ€¦ Which now that I think about it is probably more than enough reasonâ€¦ But interested to hear your thoughts

And the direct numerical comparisons is also a great suggestion that I think youâ€™ve mentioned to me beforeâ€¦ One day it will sink in

1 Like

Yeah, I think itâ€™s generally better to keep everything self contained if you can. I used to use a lot of Apps Script when I first started with Glide, but these days I try to avoid it and will only use when absolutely necessary. In fact, my preference these days is to build exclusively with native tables. Not always possible, of course, but thatâ€™s what I do if I have the choice.

Just another note about passing dates as integers. Another reason to do that - probably the most compelling reason - is that it eliminates the possibility of being tripped up by variations in date formatting across user devices. That one is a real gotcha that can be really hard to debug.

3 Likes

Agreed. You present a tidy solution within Glide itself, but I prefer to avoid scripts if I can. As @Darren_Murphy mentions, keeping things self contained produces more responsive UX.

Nicely done

1 Like