Skip to main content

Overview

Integrating analytics tracking involves three parts:
  1. Install tracking script & Verify - Create an analytics embed, add the tracking script to your site, and verify it’s working
  2. Identify Users - Link the anonymous_id (generated by the script) to known users in your system with the customer_id from Pocketflows
  3. Send Conversions - Report conversion events when users complete purchases (same set up as triggers)

Prerequisites

  • A valid project_id and secret_key for API authentication
  • An existing business_id for the business you want to track

Authentication

All API requests use Basic HTTP authentication. Pass your project_id as the username and secret_key as the password.
Authorization: Basic base64(project_id:secret_key)
Content-Type: application/json

Install tracking script

An analytics embed represents a tracking instance for a specific business website. It generates the unique script URL you’ll install on your site and stores the website_url for installation verification.

Step 1: Create an Analytics Embed

Request

POST /businesses/{business_id}/analytics_embeds

Headers
{
  "Authorization": "Basic base64encode(project_id:secret_key)",
  "Content-Type": "application/json"
}

Body
{
  "website_url": "https://example.com"
}

Parameters

website_url - The URL where the tracking script will be installed

Response

{
  "id": "ae_WWWWXXXXXYYYYYYZZZZZ",
  "business": "biz_abc123",
  "created_at": "2025-01-09T12:00:00Z",
  "expires_at": "2125-01-09T12:00:00Z",
  "website_url": "https://example.com",
  "last_script_request_at": null,
  "last_event_at": null
}

Step 2: Install the Tracking Script

Add this script tag to the <head> section of your website:
<head>
  <script
    async
    src="https://api.pocketflows.com/analytics/ae_WWWWXXXXXYYYYYYZZZZZ/js"
  ></script>
</head>

Step 3: Verify Installation

Request

POST https://api.pocketflows.com/analytics_embeds/{embed_id}/check

How It Works

When you call check, we:
  1. Fetch the website_url you provided
  2. Scan the HTML for the expected script tag
  3. Update last_script_request_at if found
  4. Update last_event_at with the most recent attribution event (if any)

Response

{
  "id": "ae_WWWWXXXXXYYYYYYZZZZZ",
  "business": "biz_abc123",
  "website_url": "https://example.com",
  "last_script_request_at": "2025-01-09T14:30:00Z",
  "last_event_at": null
}

Part 2: Identify Users

Link the anonymous_id (generated by the tracking script) to a Pocketflows customer_id after the user signs up and is synced to Pocketflows.

Accessing the Anonymous ID

Once the tracking script is installed, you can access the anonymous_id from the browser:
// window
window.PocketflowsAnalytics.anonymousId;

// localStorage
localStorage.getItem("pf_anonymous_id");

// cookie
Object.fromEntries(document.cookie.split("; ").map((c) => c.split("=")))
  .pf_anonymous_id;
The script stores this ID in localStorage and cookies as pf_anonymous_id, so it persists across sessions.
Browser console showing anonymous ID access methods

Identifying Customers

After a user signs up and is synced to Pocketflows, call identify to link their anonymous session to their customer record:
window.PocketflowsAnalytics.track("identify", {
  customer: "<%= @customer.public_id %>",
});
Behind the scenes, Pocketflows:
  1. Links all previous events from this anonymous_id to the customer
  2. Associates all future events from this anonymous_id with the customer

Part 3: Send Conversions

Send purchase events the same way you send trigger events today.
Coming soon: A dashboard setting to tag which events should be considered purchase events for attribution.

How Attribution Works

When a purchase event is received, Pocketflows looks up the customer and finds their last touch point based on tracked UTM parameters like:
  1. ad_campaign_id - Google Ads or other ad platforms
  2. campaign_id - Pocketflows campaign
  3. trigger_id - Pocketflows trigger
  4. email_blast_id - Pocketflows email blast
This last-touch attribution links the conversion back to the marketing source that drove it.