Skip to content

plain-insure/dub-managed-component

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dub Managed Component

A managed component for Dub.co link tracking and ecommerce events

Dub.co

Common use is currently for Cloudflare Zaraz.

Features

  • πŸ”— Link Click Tracking: Automatically tracks clicks via Dub's click ID cookie
  • πŸ“Š Lead Tracking: Track signups, form submissions, and other conversion events
  • πŸ’° Ecommerce Tracking: Track sales, purchases, and revenue events
  • 🎯 Customer Attribution: Associate events with customers for accurate attribution
  • πŸ” Secure: Uses server-side tracking with API keys
  • ⚑ Fast: Minimal overhead with the official Dub TypeScript SDK

How to use

Zaraz / Cloudflare Worker

Until this component is an "official" Managed Component, we need to manually host the MC in a Cloudflare Worker.

  1. Clone this repository
  2. Install dependencies with pnpm install
  3. Build the component with pnpm run build
  4. Deploy to Cloudflare Workers:
    CLOUDFLARE_ACCOUNT_ID=<YOUR_ACCOUNT_ID> \
    CLOUDFLARE_API_TOKEN=<YOUR_API_TOKEN> \
    CLOUDFLARE_EMAIL=<YOUR_EMAIL> \
    pnpm run release
  5. Follow the prompts to setup the Worker
  6. Login to the Cloudflare dashboard and go to the Zaraz Dashboard
  7. Choose Custom Managed Component
  8. Select custom-mc-zaraz-dub from the list
  9. Grant Server network requests permission (required for API calls)
  10. Grant Access client key-value store permission (recommended for click tracking)
  11. Configure your Dub API Key in the tool settings

Configuration

Tool Settings

Dub API Key string (required)

Your Dub API key. You can find this in your Dub workspace settings.

Dub Workspace ID string (optional)

The ID of the Dub workspace you want to send events to.

Events

Pageview Tracking

Pageviews are automatically tracked as lead events:

// Automatic - no code needed

Lead Tracking

Track signups, registrations, and other lead events:

zaraz.track('track', {
  eventName: 'Sign Up',
  customerExternalId: 'user_123',
  customerEmail: '[email protected]',
  customerName: 'John Doe',
})

Ecommerce/Sale Tracking

Track purchases and revenue:

zaraz.track('ecommerce', {
  eventName: 'Purchase',
  customerExternalId: 'user_123',
  amount: 9999, // Amount in cents (e.g., $99.99)
  currency: 'USD',
  invoiceId: 'inv_abc123',
  paymentProcessor: 'stripe',
  metadata: {
    productId: 'prod_123',
    plan: 'premium',
  },
})

Identify User

Associate a customer ID with the current session:

zaraz.track('identify', {
  customerId: 'user_123',
  customerEmail: '[email protected]',
  customerName: 'John Doe',
})

Event Fields

Lead Event Fields

Field Type Required Description
eventName string Yes Name of the lead event
customerExternalId string Yes Unique customer ID in your system
customerEmail string No Customer's email address
customerName string No Customer's name
customerAvatar string No URL to customer's avatar image
eventQuantity number No Number of times to track this event
metadata object No Additional metadata (max 10,000 characters)

Sale Event Fields

Field Type Required Description
customerExternalId string Yes Unique customer ID in your system
amount number Yes Sale amount in cents (or full value for zero-decimal currencies)
currency string No ISO 4217 currency code (default: USD)
eventName string No Name of the sale event
paymentProcessor string No Payment processor used (e.g., 'stripe')
invoiceId string No Invoice/transaction ID (used for deduplication)
leadEventName string No Name of the lead event to attribute this sale to
customerEmail string No Customer's email address
customerName string No Customer's name
customerAvatar string No URL to customer's avatar image
metadata object No Additional metadata (max 10,000 characters)

Component Development

Released under the Apache license PRs welcome! code style: prettier

Prerequisites

  1. Make sure you're running Node.js (>=18.0.0) and pnpm (>=8.0.0)
  2. Install dependencies with pnpm install

Development Scripts

  • pnpm run dev - Build with watch mode
  • pnpm run test - Run tests once
  • pnpm run test:dev - Run tests in watch mode
  • pnpm run lint - Lint code
  • pnpm run lint:fix - Lint and auto-fix issues
  • pnpm run typecheck - Type check TypeScript
  • pnpm run build - Full build (lint, typecheck, test, bundle)
  • pnpm run release - Deploy to Cloudflare Workers

Testing

Run tests with:

pnpm run test

Or in watch mode:

pnpm run test:dev

Deployment

Deploy to Cloudflare Workers:

pnpm run release

Then configure it in the Cloudflare Zaraz Dashboard.

Resources

Support

License

Licensed under the Apache License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors