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

rabbit-analytics

v1.2.7

Published

A custom analytics service for Shopify and WooCommerce platforms.

Downloads

8

Readme

Analytics Service Library

This library provides an abstract AnalyticsService class and two concrete implementations: ShopifyAnalyticsService and WooCommerceAnalyticsService. It includes a factory (AnalyticsFactory) to instantiate the appropriate analytics service based on the platform.

Installation

Install the package using npm:

npm install rabbit-analytics

Usage

Importing the Library

First, import the necessary classes from the package:

const AnalyticsFactory = require('rabbit-analytics');

Creating an Analytics Service

Use the AnalyticsFactory to create an instance of the analytics service for a specific platform:

const analyticsService = AnalyticsFactory.create('Shopify');

Supported platforms:

  • Shopify
  • WooCommerce

Methods

Each analytics service implements the following methods:

track(event, properties)

Tracks a specific event with optional properties.

const analyticsService = AnalyticsFactory.create('Shopify');

analyticsService.track('Product Viewed', {
  productId: '12345',
  productName: 'Cool T-Shirt',
  category: 'Apparel',
});

Parameters:

  • event (string): The name of the event to track.
  • properties (object): An optional object containing additional event properties.

Example:

// Tracking a purchase event
analyticsService.track('Purchase Made', {
  orderId: '98765',
  amount: 49.99,
  currency: 'USD',
});

identify(userId, traits)

Identifies a user with a unique ID and optional traits.

const analyticsService = AnalyticsFactory.create('WooCommerce');

analyticsService.identify('user-123', {
  email: '[email protected]',
  name: 'John Doe',
  subscriptionLevel: 'Premium',
});

Parameters:

  • userId (string): The unique ID of the user.
  • traits (object): An optional object containing user traits.

Example:

// Identifying a user with additional traits
analyticsService.identify('user-456', {
  email: '[email protected]',
  name: 'Jane Doe',
  registeredAt: '2024-01-01',
});

page(pageName)

Tracks page views with optional properties.

const analyticsService = AnalyticsFactory.create('Shopify');

analyticsService.page('Homepage');

Parameters:

  • pageName (string): The name of the page being viewed. If not provided, the current document title will be used.

Example:

// Tracking a product page view
analyticsService.page('Product Detail Page');

Implementation Details

Abstract AnalyticsService Class

The AnalyticsService class is an abstract base class with the following methods:

  • track(event, properties): Should be implemented by subclasses to track events.
  • identify(userId, traits): Should be implemented by subclasses to identify users.
  • page(pageName): Should be implemented by subclasses to track page views.

Concrete Implementations

ShopifyAnalyticsService

Implements the AnalyticsService methods for Shopify.

  • track(event, properties): Logs events with Shopify-specific properties.
  • identify(userId, traits): Logs user identification with Shopify-specific traits.
  • page(pageName): Logs page visits with Shopify-specific properties.

WooCommerceAnalyticsService

Implements the AnalyticsService methods for WooCommerce.

  • track(event, properties): Logs events with WooCommerce-specific properties.
  • identify(userId, traits): Logs user identification with WooCommerce-specific traits.
  • page(pageName): Logs page visits with WooCommerce-specific properties.

Factory Class

AnalyticsFactory

  • create(platform): Creates an instance of the analytics service for the specified platform. Supported platforms are Shopify and WooCommerce.

Example:

const shopifyService = AnalyticsFactory.create('Shopify');
const wooCommerceService = AnalyticsFactory.create('WooCommerce');

License

This project is licensed under the MIT License - see the LICENSE file for details.


This Markdown content provides a complete and detailed overview of how to use the analytics service library. You can copy this content into a `README.md` file in your project directory.