Source: https://datafa.st/docs/api-get-visitor
Markdown source: https://datafa.st/docs/api-get-visitor.md
Description: API endpoint to retrieve detailed information about a specific visitor.

# Get visitor data

`GET https://datafa.st/api/v1/visitors/{datafast_visitor_id}`

Retrieve identity, activity, and prediction data for a specific `datafast_visitor_id`. Requires [Bearer Token](/docs/api-introduction) authentication.

## Response

- **Success (200 OK):** Returns a detailed visitor data object.
- **Errors:** See [API Introduction](/docs/api-introduction). A 400 occurs if the visitor is a bot.

## Response fields

See the example response for the structure. Key objects:

- **`identity`**: Geo-location, device, browser, OS, and first-session parameters derived from the latest pageview.
- **`activity`**: Visit/pageview counts, timing, last URL, completed custom goals, and a list of visited pages.
- **`profile`**: Latest Identify profile for this visitor, including `userId`, custom metadata, and `identifiedAt`. Present only when the visitor has been identified.
- **`prediction`**: Conversion prediction details (rate, USD value, score, confidence). Null if visitor is already a customer or you haven't set up [revenue attribution](/docs/revenue-attribution-guide).

> Use `prediction` to get more sales: Show a lead magnet or coupon to low-converting visitors, or create urgency or exclusivity to high-potential visitors.

## Code examples

### Example request (Node.js/Express)

```javascript
// Your backend API endpoint
const handler = async (req, res) => {
  const datafast_visitor_id = req.cookies.datafast_visitor_id;

  try {
    const response = await fetch(`https://datafa.st/api/v1/visitors/${datafast_visitor_id}`, {
      method: "GET",
      headers: {
        Authorization: `Bearer ${DATAFAST_API_KEY}`,
        "Content-Type": "application/json",
      },
    });

    const result = await response.json();

    res.status(200).send(result);
  } catch (error) {
    console.error("Error sending goal to DataFast:", error);
    res.status(500).send("Failed to track goal");
  }
};
```

### Success response (200 OK)

```json
{
    "status": "success",
    "data": {
        "visitorId": "a3ab2331-989f-4cfa-91c6-2461c9e3c6bd",
        "identity": {
            "country": "KR",
            "countryCode": "KR",
            "region": "KR-44",
            "city": "Seosan City",
            "params": {  "ref": "youtube.com", "source": null, "utm_source": null, "utm_medium": null, "utm_campaign": null, "utm_content": null, "utm_term": null },
            "browser": { "name": "Chrome", "version": "133.0.0.0" },
            "os": { "name": "Mac OS", "version": "10.15.7" },
            "device": { "type": "desktop", "vendor": "Apple", "model": "Macintosh" },
            "viewport": { "width": 1728, "height": 998 }
        },
        "profile": {
            "userId": "user@example.com",
            "metadata": {
                "name": "Jane Doe",
                "plan": "pro"
            },
            "identifiedAt": "2025-04-11T03:39:10.000Z"
        },
        "activity": {
            "visitCount": 3,
            "pageViewCount": 8,
            "timeSinceFirstVisit": 3296041, // in milliseconds
            "timeSinceCurrentVisit": 3296041, // in milliseconds
            "firstVisitAt": "2025-04-11T03:38:49.154Z",
            "lastVisitAt": "2025-04-11T03:38:49.154Z",
            "currentUrl": "codefa.st/",
            "visitedPages": [
                {
                    "url": "codefa.st/",
                    "timestamp": "2025-04-11T03:38:49.154Z"
                },
            ]
            "completedCustomGoals": [
                {
                  "name": "newsletter_signup",
                  "description": "Sign up for the newsletter",
                  "isServer": false, // true if the goal was created using DataFast API
                  "timestamp": "2025-04-11T03:38:54.253Z"
                },
            ],
           
        },
        "prediction": {
            "score": 72, // (0-100) how likely is this visitor to convert? 50 is your baseline/average, 100 is very likely to convert, 0 is very unlikely to convert
            "conversionRate": 0.0138, // predicted conversion rate (1.38% chance to convert here)
            "expectedValue": 3.089, // predicted revenue in USD (predicted conversion rate * predicted order value)
            "confidence": 0.831, // (0-1) our confidence level based on data points analyzed. The higher the number, the more accurate the predictions. don't make important decisions if confidence is <0.5
        }
    }
}
```
