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 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-track-activity

v1.0.0

Published

Utility function to track browsing activity in a Chrome extension

Downloads

3

Readme

chrome-track-activity

Utility function to track browsing activity in a Chrome extension.

Usage

This package exports a single function startTrackingActivity which can be used to track a user's browsing activity.

The following example demonstates its usage:

function onSessionStart(session) {
  console.log("START", session.startTime, session.url);
}

function onSessionEnd(session) {
  console.log("END", session.endTime, session.url);
}
var stopTracking = startTrackingActivity(onSessionStart, onSessionEnd);

startTrackingActivity accepts two arguments:

  1. onSessionStart: Invoked each time the user loads a new page in the foreground tab or navigates to an existing page. The argument session contains the url, startTime and tabId for the new page.

  2. onSessionEnd: Invoked each time the user loads a new page in the foreground tab, changes the tab or window, closes the foreground tab, or leaves the browser window. The argument session contains the url, startTime, tabId and endTime for the page that was closed/changed.

The return value of startTrackingActivity is another function, which can called to discontinue tracking when it is no longer required.

Installation

IMPORTANT NOTE: To use startTrackingAcvitity, you need to declare the "tabs" permission in your extension's manifest file.

Method 1: Copy-paste

The easiest way to add the utility startTrackingActivity is to copy-paste the code from tracking.js into your background script/page. It's only 70 lines!

Method 2: <script> tag

First download the the file into your extension directory using the following command:

curl -O https://raw.githubusercontent.com/aakashns/chrome-track-activity/master/tracking.js

Then include it in your background page using a script tag:

<head>
   <script src="tracking.js"></script>
</head>

Check out the example for an example of this approach.

Method 3: Install from npm

Install the package from npm by running:

npm install chrome-track-activity --save

Then include it in your script using require:

var startTrackingActivity = require('chrome-track-activity');

Running the Example

The example directory contains and example extension which uses startTrackingActivity to log the browsing activity of the user.

First, clone the repository:

git clone https://github.com/aakashns/chrome-track-activity.git

Then, follow the instructions on this page to load the extension into your browser.

Then, visit chrome://extensions and inspect the background page:

Open the 'Console' tab, leave the inspector window, and continue using the browser normally. You should see a log of the browsing activity as you enter and leave pages, like this:

The logic for the extension lives is background.js.