
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@trainerday/analytics-client
Advanced tools
A lightweight JavaScript analytics client library with offline support for Hybrid and Progressive Web Apps
A lightweight (2.9k) JavaScript analytics client library with offline support for Hybrid and Progressive Web Apps.
This library provides a simple API for tracking events and user properties, compatible with popular analytics service endpoints. Events are written to localStorage first and are only removed once the analytics API confirms receipt, thus allowing the device to go offline without losing events.
Note: This client library can be used with self-hosted analytics APIs (like TrainerDay's analytics-api) or any compatible analytics service endpoint.
To use with TrainerDay's analytics-api:
// Initialize with your self-hosted API endpoints
analytics.init('your-analytics-token', {
trackingUrl: 'https://your-domain.com/track?data=',
engageUrl: 'https://your-domain.com/engage?data='
});
// All existing code works unchanged
analytics.track('Event Name', { property: 'value' });
analytics.identify('user@email.com');
Demo: The analytics-api project includes a complete demo page at /demo/index.html
showing integration examples.
npm install @trainerday/analytics-client
<script src="https://unpkg.com/@trainerday/analytics-client@latest/dist/analytics-client.min.js"></script>
Download analytics-client.min.js and add to your project:
<script src="analytics-client.min.js"></script>
At present only the following methods are supported:
// Alias for cleaner code
var analytics = mixpanel;
// setup analytics client
analytics.init('your-token-here'); // pass { mute: true } to mute by default
// assign all future events to a user
analytics.identify('user@email.com');
// register 'Gender' as a super property
analytics.register({'Gender': 'Female'});
// assign user info
analytics.people.set({
$email: 'user@email.com' // only special properties need the $
});
// track an event
analytics.track('Your Event Name' {
firstName: 'Optional event property 1',
lastName: 'Optional event property 2'
});
// clear current identity
analytics.reset();
// stop sending data to analytics (calls to track, identify etc are ignored)
analytics.mute();
// resume sending data to analytics
analytics.unmute();
// check if analytics is muted
if (analytics.muted) {
console.log('Analytics is disabled');
}
Pull requests are welcomed:
git checkout -b my-new-feature
git commit -m 'Add some feature'
git push origin my-new-feature
analytics-client uses window.localStorage
and window.Promise
which should exist in all modern browsers.
To generate a new analytics-client.min.js from source, tweak the version number in package.json
and run:
npm run build
Star the repo if you find this useful as it helps me prioritize which bugs I should tackle first.
For change-log, check releases.
Licensed under MIT License © John Doherty
FAQs
A lightweight JavaScript analytics client library with offline support for Hybrid and Progressive Web Apps
The npm package @trainerday/analytics-client receives a total of 21 weekly downloads. As such, @trainerday/analytics-client popularity was classified as not popular.
We found that @trainerday/analytics-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.