Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"Bash(npx tsc:*)",
"Bash(rm:*)",
"Bash(pnpm remove:*)",
"Bash(pnpm build:*)"
"Bash(pnpm build:*)",
"Bash(npm whoami:*)",
"Bash(npm publish:*)",
"Bash(npm view:*)"
],
"deny": [],
"ask": []
Expand Down
11 changes: 11 additions & 0 deletions .github/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 142 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Analytics 🧮
<p align="center">
<img src=".github/assets/logo.svg" alt="Analytics Logo" />
</p>

[![npm version](https://img.shields.io/npm/v/@jadecubes/analytics.svg)](https://www.npmjs.com/package/@jadecubes/analytics)
[![Build Status](https://img.shields.io/github/actions/workflow/status/jadecubes/Analytics/ci.yml)](https://github.com/jadecubes/Analytics/actions)
[![License](https://img.shields.io/npm/l/@jadecubes/analytics.svg)](LICENSE)
<p align="center">

> A unified TypeScript library for tracking analytics across **Google Analytics 4**, **Meta (Facebook) Pixel**, and **TikTok Pixel**, built for React applications and beyond.
[![npm version](https://img.shields.io/npm/v/@jadecubes/analytics.svg)](https://www.npmjs.com/package/@jadecubes/analytics)
[![npm downloads](https://img.shields.io/npm/dm/@jadecubes/analytics.svg)](https://www.npmjs.com/package/@jadecubes/analytics)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.6-blue)](https://www.typescriptlang.org/)
[![React](https://img.shields.io/badge/React-18.3-blue)](https://reactjs.org/)

</p>

<p align="center">
<b>A unified TypeScript library for tracking analytics across Google Analytics 4, Meta (Facebook) Pixel, and TikTok Pixel</b>
</p>

<p align="center">
Built for React applications and beyond
</p>

---

Expand All @@ -15,14 +29,14 @@ Modern front-ends often require multiple analytics platforms. Analytics offers:
- **Lazy loading** of tracking scripts and automatic queueing of events.
- Built with **TypeScript**, offering type definitions out of the box.
- Designed for **React** (hooks + context) but easy to adapt.
- Built in an **Nx monorepo** for reuse across apps.
- Built with **Vite** for optimal bundle size and performance.

---

## 🧑‍💻 Who Should Use It?

- Front-end engineers using React who want to track events across multiple analytics platforms.
- Teams managing **monorepos** (e.g., Nx, Turborepo) and looking for a shared analytics lib.
- Teams looking for a shared analytics library with a consistent API.
- Developers who want a lightweight, configurable alternative to multiple SDKs.

---
Expand All @@ -37,3 +51,124 @@ npm install @jadecubes/analytics

# or with pnpm / yarn
pnpm add @jadecubes/analytics
yarn add @jadecubes/analytics
```

---

## 📦 Publishing to npm

This library is published as `@jadecubes/analytics` on npm. If you're a maintainer, follow these steps to publish a new version:

### Prerequisites

1. **npm Account**: Ensure you have an npm account and are logged in
```bash
npm login
```

2. **Organization Access**: You need publish access to the `@jadecubes` organization on npm

### Publishing Steps

1. **Update Version**: Update the version in `libs/analytics/package.json` following [semantic versioning](https://semver.org/):
- **Patch** (0.0.x): Bug fixes
- **Minor** (0.x.0): New features, backward compatible
- **Major** (x.0.0): Breaking changes

```bash
# Edit libs/analytics/package.json and update the version field
# For example: "version": "0.0.2"
```

2. **Build the Library**:
```bash
pnpm build
```

3. **Test the Build**: Verify the build output in `dist/libs/analytics/`
```bash
ls -la dist/libs/analytics/
```

4. **Copy package.json to dist**: The package.json needs to be in the dist directory
```bash
cp libs/analytics/package.json dist/libs/analytics/
```

5. **Publish to npm**:
```bash
cd dist/libs/analytics
npm publish --access public
```

### Automated Publishing (Recommended)

You can add a publish script to your root `package.json`:

```json
{
"scripts": {
"publish:analytics": "pnpm build && cp libs/analytics/package.json dist/libs/analytics/ && cd dist/libs/analytics && npm publish --access public"
}
}
```

Then simply run:
```bash
pnpm publish:analytics
```

### Publishing Beta/Alpha Versions

For pre-release versions:

```bash
# Update version to include tag, e.g., "0.1.0-beta.1"
cd dist/libs/analytics
npm publish --access public --tag beta
```

---

## 🛠️ Development

### Project Structure

```
Analytics/
├── libs/
│ └── analytics/ # Main analytics library
│ ├── src/
│ │ ├── core/ # Core analytics implementations
│ │ ├── react/ # React-specific providers
│ │ └── types/ # TypeScript types
│ └── vite.config.ts # Vite build configuration
├── docs/ # Documentation (Storybook)
└── tools/ # Build and development tools
```

### Available Scripts

```bash
# Build the library
pnpm build

# Run tests
pnpm test

# Lint code
pnpm lint

# Run Storybook for documentation
pnpm storybook

# Build Storybook
pnpm build-storybook
```

---

## 📄 License

MIT License - see [LICENSE](LICENSE) file for details
41 changes: 0 additions & 41 deletions docs/README.md

This file was deleted.

38 changes: 36 additions & 2 deletions libs/analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,46 @@
{
"name": "analytics",
"name": "@jadecubes/analytics",
"version": "0.0.1",
"description": "A unified TypeScript library for tracking analytics across Google Analytics 4, Meta (Facebook) Pixel, and TikTok Pixel",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
"require": "./index.js",
"types": "./index.d.ts"
}
},
"files": [
"index.js",
"index.mjs",
"index.d.ts",
"**/*.d.ts"
],
"keywords": [
"analytics",
"google-analytics",
"ga4",
"facebook-pixel",
"meta-pixel",
"tiktok-pixel",
"tracking",
"react",
"typescript"
],
"author": "jadecubes",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jadecubes/Analytics.git",
"directory": "libs/analytics"
},
"bugs": {
"url": "https://github.com/jadecubes/Analytics/issues"
},
"homepage": "https://github.com/jadecubes/Analytics#readme",
"peerDependencies": {
"react": "^18.0.0"
}
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
"prepare": "husky",
"dev": "vite",
"build": "cd libs/analytics && tsc --noEmit && vite build",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0 --ignore-pattern 'eslint.config.mjs'",
"preview": "vite preview",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"publish:analytics": "pnpm build && cp libs/analytics/package.json dist/libs/analytics/ && cd dist/libs/analytics && npm publish --access public"
},
"dependencies": {
"react": "^18.3.1",
Expand Down