npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@janiscommerce/app-tracking-time

v2.3.0

Published

A package for managing the times of actions in applications

Downloads

51

Readme

@janiscommerce/app-tracking-time

janis-logo

This package manages events in your application by interacting with a database. It provides functionalities to add, retrieve, and validate events. Also handles application state changes to pause ongoing events when the app goes into the background.

Dependencies

To ensure the proper functioning of this library, make sure that the following dependencies are installed in your project:

Required Peer Dependencies

  • date-fns: >=2.0.0 <3.0.0
  • react: >=18.2.0
  • react-native: >=0.71.5
  • realm: ^11.0.0

These dependencies are required for the library to work correctly. Ensure that your project has these versions installed to avoid compatibility issues.

Installation

npm i @janiscommerce/app-tracking-time

How to use?

First, creates a new instance of the EventTracker class and declare the name for the database:

import EventTrackerClass from '@janiscommerce/app-tracking-time';

const EventTracker = new EventTrackerClass('events_database')

export default EventTracker;

Save your first record:

To save an event you must call the addEvent method of the EventTracker class and pass it an object with the following parameters:


const saveInitEvent = async (id) => {
    try {
        await EventTracker.addEvent({id,type:'start'})
    } catch(error) {
        console.warn(error);
    }
}


<Button title='save new event' onPress={() => saveInitEvent('66e99577e128deb19d57cd74')}/>

This action will save a start type event associated with the id 66e99577e128deb19d57cd74

Search all events associated with your id:

To get all the records you saved related to an id, you can call the getEventsById function:

const fetchEventsById = async (id) => {
    try {
        const [events, fetchError] = await promiseWrapper(EventTracker.getEventsById(id))

        console.log(events);
    } catch(error) {
        console.warn(error);
    }
}


<Button title='fetch events' onPress={() => fetchEventsById('66e99577e128deb19d57cd74')}/>

Delete all events of an id:

You can delete all records of an id using the deleteEventsById.

This method will be responsible for eliminating all the events that have been registered that have the id that you pass as an argument

const deleteEvents = async (id) => {
    try {
        await EventTracker.deleteEventsById(id)
    } catch(error) {
        console.warn(error);
    }
}


<Button title='remove events' onPress={() => deleteEvents('66e99577e128deb19d57cd74')}/>

The cleanup method will be called once the component is unmounted and will unlisten for state changes from the app. If any of the events you want to pause is already paused, what will happen is that the console will throw a warning with the error reported by the package.

Sequence of recorded events

The package has internal validations that prevent events from being saved consecutively or that do not have coherence depending on the event that has been saved prior to this one. For example, you will not be able to store 2 pause type events consecutively. Additionally, saving any event related to an ID that has already been finished is also not allowed.

If you want to know what was the last event that was stored for a particular id, you can call the getLastEventById method, which will return an object with the information of the last stored event, including the type.