# Analytics

## Pirsch

### Setup

1. Create a new site on [Pirsch](https://pirsch.io/ref/beJar7BgQM)
2. Set the data-code in the Pirsch script tag in `layout.ts`

```html
<script
    defer
    type="text/javascript"
    src="/pirsch-extended.js"
    id="pirschextendedjs"
    data-code=""
/>
```

### Safe routing

Some browsers and ad-blockers might block the requests to the Pirsch javascript file.

To avoid that, **Shipped** includes a rewrite rule in `next.config.js`

```javascript
async rewrites() {
  return [
    {
      source: "/pirsch-extended.js",
      destination: "https://api.pirsch.io/pirsch-extended.js",
    },
  ];
},
```

This rule is already included, so no action from you is required.

### Extra

Pirsch allows you to track specific events on the page. See the [documentation](https://docs.pirsch.io/advanced/events?ref=shippedclub).

## SimpleAnalytics

[SimpleAnalytics](https://www.simpleanalytics.com/?ref=shippedclub) is another popular analytics product.

To enable add this code to the `layout.ts` file

```typescript
import Script from "next/script"


export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        /* ... */
        <Script src="/simple-analytics.js" />
        <noscript>
          <img
            src="/simple-analytics-noscript.gif"
            alt=""
            referrerPolicy="no-referrer-when-downgrade"
          />
        </noscript>
      </head>
      <body className={inter.className}>
        <Providers>{children}</Providers>
      </body>
    </html>
  );
}
```

Then update `next.config.js`

```javascript
async rewrites() {
  return [
    {
      source: "/simple-analytics.js",
      destination: "https://scripts.simpleanalyticscdn.com/latest.js",
    },
        {
      source: "/simple-analytics-noscript.gif",
      destination: "https://queue.simpleanalyticscdn.com/noscript.gif",
    },
  ];
},
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shipped.club/features/analytics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
