← Developer Portal

Integration guide · Tideflow AI

Add analytics and track views and conversions

Install the browser tracker, record meaningful actions, and connect conversions to the pages that brought visitors to your website.

Get your project’s installation code

Open your project’s Settings in Tideflow AI and find the analytics installation instructions. Copy the snippet generated for that project and website. If your coding agent is connected through MCP, it can request the same setup using get_analytics_setup. Choose script for HTML, react for React or Next.js, or javascript for a JavaScript entry point.

The tool returns integration.snippet and integration.placement, plus the tracking function, supported options, and examples. Use that generated snippet: it contains the installation token scoped to your project’s origin and path. A preview domain or a different website needs matching setup; do not reuse a token and assume it covers every deployment.

json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "get_analytics_setup",
    "arguments": {
      "target": "script"
    }
  }
}

Install the tracker once

For static HTML or a server-rendered template, place the generated script in the head of every page you want to measure. The example below shows its shape; replace YOUR_SITE_TOKEN with the installation token from your setup. This browser installation token is intended for the page. It is not your private MCP credential or crawler secret.

For React and Next.js, request target: react instead. Save the returned client component and mount it once near the application root. The generated component checks for an existing script before adding another one. All three installation targets load the same tracker.

html
<script
  defer
  src="https://events.tideflow.ai/tideflow.js"
  data-site-token="YOUR_SITE_TOKEN"
></script>

Let page views track automatically

The tracker records the initial page load and SPA history changes automatically. Do not send $pageview yourself or install a second tracker for client-side navigation. Named events beginning with $ are reserved.

The tracker uses an anonymous first-party identifier and starts a new session after 30 minutes of inactivity. It respects Do Not Track and Global Privacy Control. If browser storage or collection is blocked, your website continues to work, but those visits may not appear in analytics.

Record conversions after success

Call window.tideflow.track after a meaningful action has actually succeeded—for example, after an account is created, a lead is accepted, or a purchase is confirmed. A button click alone does not establish that outcome. Only events with conversion: true count as conversions; repeated calls count separately, so avoid firing again on rerenders or confirmation-page refreshes.

Optional chaining keeps tracking from breaking the page if the script is unavailable. It does not queue an event that fires before the tracker is ready. Place calls in your completed-action handlers after installation.

javascript
// Inside the successful signup handler:
window.tideflow?.track("signup", { conversion: true });

// Inside the confirmed purchase handler:
window.tideflow?.track("purchase", {
  conversion: true,
  value: 49,
  currency: "USD"
});

// A named event that is not a conversion:
window.tideflow?.track("pricing_viewed");

Use the supported event fields

Event names must be 1–64 characters, start with a letter, and then use letters, digits, underscores, periods, colons, or hyphens. Supported options are conversion (boolean), value (a finite number), currency (a three-letter code such as USD), and unit (an optional value unit of up to 32 characters). Arbitrary user properties are not part of this contract.

Use an event name such as lead_submitted rather than embedding an email address or customer name. The collector normalizes page URLs and removes query strings and fragments before analytics storage.

Verify collection and attribution

Open the deployed site, navigate between pages, and complete one test action. In browser developer tools, confirm tideflow.js loads and inspect collection requests to events.tideflow.ai/v1/collect. If nothing is sent, check privacy settings, blockers, your content security policy, and whether the script is installed. If requests are rejected, check the project token and the site’s origin and path. Do not disable a visitor’s privacy choices.

In Tideflow AI, open Website analytics for the matching project and date range. Compare page views with the named conversion events you sent. Page views belong to the URL viewed; conversions and AI referrals are attributed to the session’s landing page. A person can arrive on an article and convert elsewhere while the article retains landing-page attribution. Referrals depend on identifiable source information, so not every AI-originated visit can be recognized.

Explore more in Developer Portal →