Seedy Pea

Seedy Pea Docs

Seedy Pea has three public developer surfaces:

Use the edge package when you can. It keeps visitor identity in a first-party HttpOnly cookie, forwards events from your own origin, and gives the browser package a small same-origin endpoint.

Use direct browser mode when you need the fastest possible install and can accept a localStorage anonymous id.

Quickstart

Install the two packages:

npm install seedypea seedypea-client

Add a first-party collector in your edge runtime:

import { pea } from "seedypea";

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    const sp = pea(request, env);

    if (url.pathname === "/sp/events") {
      return sp.cooked.collect(request);
    }

    if (url.pathname === "/sp/profile") {
      return sp.cooked.serveProfile(request);
    }

    if (url.pathname === "/sp/profile/delete") {
      const upstream = await sp.cooked.forgetProfile(request);
      return sp.cookie.clear(upstream);
    }

    const response = await env.ASSETS.fetch(request);
    return sp.cookie.apply(response);
  }
};

Initialize the browser client against the edge endpoint:

import { init, pageView, track } from "seedypea-client";

init({ endpoint: "/sp/events" });
pageView();

track("AddToCart", {
  item: "pants",
  size: "xxl"
});

Required edge environment:

SEEDYPEA_PROJECT_ID=proj_...
SEEDYPEA_WRITE_KEY=wk_...

Read seedypea for edge helpers, seedypea-client for browser collection and declarative bindings, and HTTP API when you are calling Seedy Pea without the packages.