electerious / ackee-tracker

Transfer data to Ackee.
MIT License
196 stars 22 forks source link

Allow instance ID to be saved to localStorage #18

Closed emschwartz closed 3 years ago

emschwartz commented 4 years ago

I have a use case where I expect that users may reload the webpage but I would like to treat all of their time spent across multiple tab reloads as part of the same visit.

Would it be possible to expose an ID on the instance that could be saved to localStorage and set on a new instance if the page is reloaded?

emschwartz commented 4 years ago

@electerious any thoughts on this?

electerious commented 4 years ago

Sounds like a good idea, but it might require some refactoring as the instance can't return the id immediately (only async). Ackee v2 will ship with a new ackee-tracker. I will change the return value of the instance to an object instead of the stop-function before releasing the next version. This makes it easier to implement such features in the future without making it a breaking change.

emschwartz commented 4 years ago

What do you think about this approach? https://github.com/electerious/ackee-tracker/pull/19 I tried to modify the structure as little as possible. If you like the approach I can clean up the PR and add the methods to the docs.

emschwartz commented 4 years ago

Actually another way to go would be to have an option that would store the recordId in sessionStorage and use that if it's saved there. Any preference?

electerious commented 4 years ago

Thanks for the PR! Will take a closer look at it when I work on events as the id feature itself doesn't have a big priority for now. I recommend to use your fork in the meantime.

The events (https://github.com/electerious/Ackee/issues/40#issuecomment-678634751) also need an update function and a way to get the id which I will probably do in the same way.

electerious commented 3 years ago

Implemented the updateRecord function on the events branch (not tested, yet).

electerious commented 3 years ago

This feature has been implemented in v5 (will ship along with Ackee v3). I've added a callback to the record function so it's possible to obtain the recordId and a new function called .updateRecord to start updating an existing record. Hope that helps :)

https://github.com/electerious/ackee-tracker/tree/feature/v5#updaterecordrecordid