Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Example code for onreachgoal event?

ANSWERED

Can somebody please post a little example for an onreachgoal event (e.g. daily steps)? 

Does the Fitbit Simulator allow user activity manipulation so that I will be able to test this?

Thanks in advance!

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I don't think you can test in the simulator, but here's a sample:

 

import { today, goals } from "user-activity";
goals.addEventListener("reachgoal", (goal, evt) => {
if (today.adjusted.steps >= goal.steps) {
// step goal reached
}
})

 

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

I don't think you can test in the simulator, but here's a sample:

 

import { today, goals } from "user-activity";
goals.addEventListener("reachgoal", (goal, evt) => {
if (today.adjusted.steps >= goal.steps) {
// step goal reached
}
})

 

Best Answer
0 Votes

Thank you Jon!

Is this event also being fired for active minutes goals, calories goals etc or is it only being fired when the steps goal has been reached?

Best Answer
0 Votes

It's fired for all goals, you just need to determine which have been met.

Best Answer
0 Votes

Thanks, it works perfectly on my Versa!

Best Answer
0 Votes