### Start Svelte Development Server Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/spa/README.md Run 'npm run dev' to start the development server. Use '-- --open' to automatically open the application in your browser. ```bash npm run dev # or start the server and open the app in a new browser tab npm run dev -- --open ``` -------------------------------- ### Install OneDollarStats Package Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Install the onedollarstats package using npm. ```bash npm i onedollarstats ``` -------------------------------- ### Astro Project Commands Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/mpa/README.md Common commands for managing an Astro project. Includes installing dependencies, starting a development server, building for production, and previewing the build. ```bash npm install ``` ```bash npm run dev ``` ```bash npm run build ``` ```bash npm run preview ``` ```bash npm run astro ... ``` ```bash npm run astro -- --help ``` -------------------------------- ### Initialize OneDollarStats Tracker Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Configure the AnalyticsTracker instance. Must be called once at the app entry point. Minimal setup uses defaults; full configuration allows specifying collector URL, autocollect behavior, routing preferences, page exclusions/inclusions, and development mode settings. ```typescript import { configure } from "onedollarstats"; // Minimal setup — uses default collector URL, autocollect enabled configure(); // Full configuration configure({ collectorUrl: "https://collector.onedollarstats.com/events", // default autocollect: true, // auto-track pageviews & annotated clicks (default: true) hashRouting: true, // track hash (#) route changes as pageviews (default: false) excludePages: ["/admin", "/internal/*"], // glob patterns to suppress includePages: ["/app/*"], // if set, only these paths are tracked // Dev mode: simulate a hostname while running on localhost devmode: true, // requires hostname hostname: "myapp.com" // events appear to come from this domain }); ``` -------------------------------- ### Basic Script Tag Setup for HTML/MPA Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Include the stonks.js bundle directly in your HTML for static and multi-page sites. Autocollection is enabled by default. ```html ``` -------------------------------- ### Basic Click Event Tracking Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Annotate HTML elements with `data-s-event` to automatically track click events. This basic setup tracks the event name when the element is clicked. ```html ``` -------------------------------- ### Create Astro Project with Basics Template Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/mpa/README.md Use this command to create a new Astro project initialized with the Basics starter template. This sets up a minimal Astro project. ```bash npm create astro@latest -- --template basics ``` -------------------------------- ### Create a New Svelte Project Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/spa/README.md Use 'npx sv create' to initialize a new Svelte project. Specify a directory name to create the project in a subfolder. ```bash npx sv create # create a new project in my-app npx sv create my-app ``` -------------------------------- ### configure(config?) Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Initializes the singleton AnalyticsTracker instance with user-supplied configuration. This function must be called once at the application's entry point. If called before `view()` or `event()`, it implicitly initializes the tracker with default settings. ```APIDOC ## configure(config?) ### Description Initializes the singleton `AnalyticsTracker` instance with user-supplied configuration. Must be called once at the app entry point (root layout for SPAs, every page for static sites). Calling `view()` or `event()` before `configure()` implicitly initializes the tracker with defaults. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **config** (object) - Optional - Configuration object for the tracker. - **collectorUrl** (string) - The URL where analytics events will be sent. Defaults to a predefined URL. - **autocollect** (boolean) - Enables automatic tracking of pageviews and annotated clicks. Defaults to `true`. - **hashRouting** (boolean) - Enables tracking of hash (#) route changes as pageviews. Defaults to `false`. - **excludePages** (string[]) - An array of glob patterns for paths to exclude from tracking. - **includePages** (string[]) - If set, only paths matching these glob patterns will be tracked. - **devmode** (boolean) - Enables development mode, simulating a hostname. Requires `hostname` to be set. - **hostname** (string) - The simulated hostname to use in development mode. ### Request Example ```ts import { configure } from "onedollarstats"; // Minimal setup — uses default collector URL, autocollect enabled configure(); // Full configuration configure({ collectorUrl: "https://collector.onedollarstats.com/events", // default autocollect: true, // auto-track pageviews & annotated clicks (default: true) hashRouting: true, // track hash (#) route changes as pageviews (default: false) excludePages: ["/admin", "/internal/*"], // glob patterns to suppress includePages: ["/app/*"], // if set, only these paths are tracked // Dev mode: simulate a hostname while running on localhost devmode: true, // requires hostname hostname: "myapp.com" // events appear to come from this domain }); ``` ### Response None (This function performs initialization and does not return a value). ``` -------------------------------- ### configure Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Initializes the OneDollarStats tracker with custom configuration options. This should be called on every page for static sites or at the root layout for SPAs. If not called explicitly, it will be initialized automatically when `view` or `event` is first called. ```APIDOC ## configure(config?: AnalyticsConfig) ### Description Initializes the tracker with your configuration. ### Method `configure` ### Parameters #### Request Body - **collectorUrl** (string) - Optional - URL to send analytics events. Defaults to `https://collector.onedollarstats.com/events`. - **trackLocalhostAs** (string | null) - Optional - Deprecated. Use `hostname` and `devmode`. - **hostname** (string | null) - Optional - Override event hostname (for server-side or desktop runtimes). Required for devmode. - **devmode** (boolean) - Optional - For dev testing, requires `hostname`. Defaults to `false`. - **hashRouting** (boolean) - Optional - Track hash route changes as pageviews. Defaults to `false`. - **autocollect** (boolean) - Optional - Automatically track pageviews & clicks. Defaults to `true`. - **excludePages** (string[]) - Optional - Pages to ignore for automatic tracking. Defaults to `[]`. - **includePages** (string[]) - Optional - Pages to explicitly include for tracking. Defaults to `[]`. ### Request Example ```json { "collectorUrl": "https://collector.onedollarstats.com/events", "autocollect": true, "hashRouting": true } ``` ``` -------------------------------- ### Development Mode Configuration Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Configure the script for development mode, allowing localhost traffic to be tracked as if it were a real domain using data-hostname. ```html ``` -------------------------------- ### Configure OneDollarStats Analytics Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Initialize the analytics tracker with your configuration. Ensure this is called on every page for static sites or at the root layout for SPAs. Calling `view` or `event` before `configure` will automatically initialize with default settings. ```typescript import { configure } from "onedollarstats"; // Configure analytics configure({ collectorUrl: "https://collector.onedollarstats.com/events", autocollect: true, // automatically tracks pageviews & clicks hashRouting: true // track SPA hash route changes }); ``` -------------------------------- ### Enable Dev Mode with Script Tag Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Enable dev mode for localhost tracking by adding data attributes to the script tag. This simulates a production domain and enables event flow. ```html ``` -------------------------------- ### Build Svelte Production App Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/spa/README.md Execute 'npm run build' to generate a production-optimized version of your Svelte application. ```bash npm run build ``` -------------------------------- ### Astro Project Structure Overview Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/test/mpa/README.md This is the typical folder structure for an Astro project. Key directories include `public/` for static assets and `src/` for source code like layouts and pages. ```text / ├── public/ │ └── favicon.svg ├── src/ │ ├── layouts/ │ │ └── Layout.astro │ └── pages/ │ └── index.astro └── package.json ``` -------------------------------- ### Click Event with Path and Properties Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Combine `data-s-event-path` and `data-s-event-props` to track click events with both a custom path and associated properties. ```html ``` -------------------------------- ### Enable Dev Mode with npm Package Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Activate dev mode and simulate a production hostname when using the npm package. This allows localhost tracking and displays a debug modal. ```typescript import { configure } from "onedollarstats"; configure({ devmode: true, // required: activates localhost tracking hostname: "myapp.com" // required with devmode: simulated production domain }); // Console output: "[onedollarstats] OneDollarStats connected! Tracking localhost as myapp.com" ``` -------------------------------- ### Send a Custom Event Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Record a named custom event. Accepts an optional path and/or properties object. The path defaults to the current page's path if omitted. Values in the properties object must be strings. Use `await` to ensure the event is dispatched. ```typescript import { event } from "onedollarstats"; // Simple named event await event("Purchase"); // Event with an explicit path await event("Purchase", "/product/sneakers-42"); // Event with properties (no explicit path) await event("Purchase", { amount: "99", currency: "USD", color: "green" }); // Event with both path and properties await event("Purchase", "/product/sneakers-42", { amount: "99", size: "42" }); // Expected: sends { type: "Purchase", path: "/product/sneakers-42", props: { amount: "99", size: "42" } } // Signup funnel event await event("SignupStep", "/signup", { step: "email", variant: "modal" }); ``` -------------------------------- ### Enable Hash Routing with Script Tag Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Use the data-hash-routing attribute to enable hash-based routing for Single Page Applications (SPAs). ```html ``` -------------------------------- ### Manual Tracking via Global API Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Manually track events and page views using the global `window.stonks` object's `event()` and `view()` methods. ```javascript ``` -------------------------------- ### Click Event with Properties Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Attach custom properties to a click event using `data-s-event-props`. Properties are defined as semicolon-delimited key=value pairs. ```html
Summer Sale Banner
``` -------------------------------- ### Configure Page Filtering with Glob Patterns Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Use `excludePages` and `includePages` in the `configure` function to control which pages are auto-tracked using glob-style patterns. ```typescript import { configure } from "onedollarstats"; configure({ // Block specific paths from being auto-tracked excludePages: [ "/admin", // exact match "/internal/*", // all paths under /internal/ "/preview/*" ], // Allowlist: only auto-track these paths (overrides excludePages) includePages: [ "/app/*", "/dashboard", "/checkout/*" ] }); ``` -------------------------------- ### Click Event with Custom Path Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Track a click event and specify a custom path using `data-s-event-path`. This is useful for linking clicks to specific URLs or routes. ```html View Pricing ``` -------------------------------- ### Override Path and Props via Meta Tags Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Use `` tags with names `stonks-path` and `stonks-props` to override the tracked path and view properties for the current page. ```html ``` -------------------------------- ### Attach Default Props to Pageviews Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Use the data-props attribute to attach default properties to every pageview from a specific page. ```html ``` -------------------------------- ### Colon Syntax for Event Tracking Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt The colon syntax (`data-s:event`) is supported for event tracking, which can be more framework-friendly. ```html ``` -------------------------------- ### Automatic UTM Parameter Tracking with Script Tag Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt UTM parameters from the URL are automatically parsed and attached to PageView events when using the script tag. No additional configuration is needed. ```html ``` -------------------------------- ### Manually Record a Pageview Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Send a PageView event manually. Useful when autocollect is disabled or to attach custom properties. Path and properties provided here override DOM or meta tag values. The `await` keyword ensures the event is sent before proceeding. ```typescript import { view } from "onedollarstats"; // Simple pageview using the current URL path await view(); // Pageview with an explicit path await view("/homepage"); // Pageview with custom properties (recorded against current path) await view({ plan: "pro", step: "2" }); // Pageview with an explicit path AND custom properties await view("/checkout", { step: "2", plan: "pro" }); // Expected: sends { type: "PageView", path: "/checkout", props: { step: "2", plan: "pro" } } ``` -------------------------------- ### Enable UTM Parameter Auto-collection with npm Package Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Configure the npm package to automatically collect UTM parameters from the URL on every view() call. No extra JavaScript code is required. ```typescript import { configure } from "onedollarstats"; configure({ autocollect: true }); // No extra code needed — UTM params from location.search are included automatically ``` -------------------------------- ### view(pathOrProps?, props?) Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Manually sends a `PageView` event. This function is useful when `autocollect` is disabled or when you need to associate custom properties with a specific page view. Any path or properties provided directly to this function will override values detected from DOM attributes or `` tags. ```APIDOC ## view(pathOrProps?, props?) ### Description Manually sends a `PageView` event. By default, pageviews are collected automatically; use this function when `autocollect: false` or when you need to attach custom properties to a specific view. Any path or props passed here take priority over values found on the page via DOM attributes or `` tags. ### Method `view` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **pathOrProps** (string | object) - Optional - Either an explicit path string for the pageview, or an object containing custom properties. If a string is provided, `props` must be the second argument. - **props** (object) - Optional - An object containing key-value pairs of custom properties to associate with the pageview. Values must be strings. ### Request Example ```ts import { view } from "onedollarstats"; // Simple pageview using the current URL path await view(); // Pageview with an explicit path await view("/homepage"); // Pageview with custom properties (recorded against current path) await view({ plan: "pro", step: "2" }); // Pageview with an explicit path AND custom properties await view("/checkout", { step: "2", plan: "pro" }); // Expected: sends { type: "PageView", path: "/checkout", props: { step: "2", plan: "pro" } } ``` ### Response #### Success Response (200) This function returns a Promise that resolves when the event has been successfully sent. #### Response Example None (This function returns a Promise that resolves upon successful dispatch). ``` -------------------------------- ### Autocapture Attributes Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Attributes for modifying autocapture behavior for page views and clicks. ```APIDOC ## Autocapture ### Page View Events Attributes for tags that allow modifying the sent page view: - **`data-s-path`** (Optional) - Specifies the path representing the page where the event occurred. This attribute should be set on the `` tag. - **`data-s-view-props`** (Optional) - Defines additional properties to include with the page view event. All properties from elements on the page with this attribute will be collected and sent together. ### Click Events Automatically capture clicks on elements using these HTML attributes: - **`data-s-event`** - Name of the event. - **`data-s-event-path`** (Optional) - The path representing the page where the event occurred. - **`data-s-event-props`** (Optional) - Properties to send with the event. ``` -------------------------------- ### Track Custom Events Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Track custom events using the `event` function. This function can accept different combinations of event names, paths, and properties. ```typescript import { event } from "onedollarstats"; // Simple event event("Purchase"); // Event with a path event("Purchase", "/product"); // Event with properties event("Purchase", { amount: 1, color: "green" }); // Event with path + properties event("Purchase", "/product", { amount: 1, color: "green" }); ``` -------------------------------- ### event(eventName, pathOrProps?, props?) Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Sends a named custom event to the analytics collector. You can optionally specify a path and/or a properties object. If the path is omitted, the current page's path is used by default. Property values must be strings. ```APIDOC ## event(eventName, pathOrProps?, props?) ### Description Sends a named custom event to the collector. Accepts an optional path (string) and/or properties object (key-value pairs, values must be strings). The path argument can be omitted to default to the current page's path. ### Method `event` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **eventName** (string) - Required - The name of the custom event to send. - **pathOrProps** (string | object) - Optional - Either an explicit path string for the event, or an object containing custom properties. If a string is provided, `props` must be the second argument. - **props** (object) - Optional - An object containing key-value pairs of custom properties to associate with the event. Values must be strings. ### Request Example ```ts import { event } from "onedollarstats"; // Simple named event await event("Purchase"); // Event with an explicit path await event("Purchase", "/product/sneakers-42"); // Event with properties (no explicit path) await event("Purchase", { amount: "99", currency: "USD", color: "green" }); // Event with both path and properties await event("Purchase", "/product/sneakers-42", { amount: "99", size: "42" }); // Expected: sends { type: "Purchase", path: "/product/sneakers-42", props: { amount: "99", size: "42" } } // Signup funnel event await event("SignupStep", "/signup", { step: "email", variant: "modal" }); ``` ### Response #### Success Response (200) This function returns a Promise that resolves when the event has been successfully sent. #### Response Example None (This function returns a Promise that resolves upon successful dispatch). ``` -------------------------------- ### event(eventName: string, pathOrProps?: string | Record, props?: Record) Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Sends a custom event to OneDollarStats. This function allows for detailed event tracking with optional path and custom properties. ```APIDOC ## event(eventName: string, pathOrProps?: string | Record, props?: Record) ### Description Sends a custom event to OneDollarStats. This function allows for detailed event tracking with optional path and custom properties. ### Parameters #### Parameters - **eventName** (string) - Required - Name of the event. - **pathOrProps** (string | Record) - Optional - Represents the path or custom properties. - **props** (Record) - Optional - Properties to send with the event, used when `pathOrProps` is a string. ### Usage Example ```javascript event('user_signup', '/register', { method: 'email' }); event('product_view', { product_id: '123', category: 'electronics' }); ``` ``` -------------------------------- ### Manual Calls Bypass Page Filters Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Manual `event()` and `view()` calls always bypass the `excludePages` and `includePages` filters, ensuring critical events are always sent. ```typescript // Manual calls are NOT affected by excludePages / includePages import { event } from "onedollarstats"; await event("AdminAction", "/admin/settings"); // always sent ``` -------------------------------- ### view Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Manually tracks a pageview event. This function can be used when `autocollect` is set to `false` or for specific tracking needs. It allows overriding automatically collected data. ```APIDOC ## view(pathOrProps?: string | Record, props?: Record) ### Description Sends a pageview event. By default, pageviews are tracked automatically. Use this function for manual tracking. ### Method `view` ### Parameters #### Path Parameters - **pathOrProps** (string | Record) - Optional - If a string, it represents the path. If an object, it represents custom properties. #### Query Parameters - **props** (Record) - Optional - Custom properties to associate with the pageview, used when the first argument is a path string. ### Request Example ```ts // Simple pageview view("/homepage"); // Pageview with extra properties view("/checkout", { step: 2, plan: "pro" }); ``` ``` -------------------------------- ### Attach View Properties via Body Attribute Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Attach properties to a pageview event using the `data-s-view-props` attribute on the `` tag. These properties are merged with other sources. ```html ``` -------------------------------- ### Track Pageviews Manually Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Manually track pageviews using the `view` function. This is useful if `autocollect` is set to `false`. Any path or properties passed to `view` take priority over page-found values. ```typescript import { view } from "onedollarstats"; // Simple pageview view("/homepage"); // Pageview with extra properties view("/checkout", { step: 2, plan: "pro" }); ``` -------------------------------- ### Multiple Elements Contributing View Props Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt View properties can be contributed by multiple elements on the page; all `data-s-view-props` attributes are merged. ```html
``` -------------------------------- ### event Source: https://github.com/drizzle-team/onedollarstats-script/blob/master/README.md Tracks custom events. This function is versatile and can accept different combinations of event names, paths, and properties to provide detailed analytics. ```APIDOC ## event(name: string, pathOrProps?: string | Record, props?: Record) ### Description Tracks custom events. This function can accept different types of arguments depending on your needs. ### Method `event` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the event to track. - **pathOrProps** (string | Record) - Optional - If a string, it represents the path associated with the event. If an object, it represents custom properties for the event. #### Query Parameters - **props** (Record) - Optional - Custom properties to associate with the event. Used when the second argument is a path string. ### Request Example ```ts // Simple event event("Purchase"); // Event with a path event("Purchase", "/product"); // Event with properties event("Purchase", { amount: 1, color: "green" }); // Event with path + properties event("Purchase", "/product", { amount: 1, color: "green" }); ``` ``` -------------------------------- ### Force Collection on a Page Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Force event collection on a page even when autocollect is globally disabled by setting `data-s-collect="true"` on the body tag. ```html ``` -------------------------------- ### Override Tracked Path via Body Attribute Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Use the `data-s-path` attribute on the `` tag to override the default tracked path for the current page. ```html ``` -------------------------------- ### Disable Autocollect with Script Tag Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Configure the script tag to disable automatic event collection, allowing for manual tracking only. ```html ``` -------------------------------- ### Disable Autocollect for a Specific Page Source: https://context7.com/drizzle-team/onedollarstats-script/llms.txt Prevent automatic event collection on a specific page by using a `` tag or a `data-s-collect="false"` body attribute. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.