Install the tracking script

Create a script in your project, then add it to your site with a script tag or the Next.js SDK. Takes a few minutes and starts collecting page views immediately.

Clakta collects data through a script — a tracking source you create inside your project and then load on your site. A project can have several: one per site, per subdomain, or per environment.

1. Create the script

Go to Project settings → Script and choose Create script.

Name

Anything that tells your scripts apart later — Main site, Landing pages, Staging.

Domains

The domains this script is allowed to send data from. Add each one without the protocol:

example.com
shop.example.com

Requests from any other domain are rejected, which keeps someone else's site (or a scraped copy of yours) from polluting your data.

Leave the list empty to allow tracking from any domain. That is convenient while you are testing, but lock it down before you rely on the numbers.

Auto-tracked events

Choose what the script records without you writing any code:

EventWhat it captures
Page viewsEvery page load, including client-side route changes.
Outbound clicksClicks on links pointing to other websites.
ScrollsHow far visitors progress down a page.
Form submissionsForm submits on your pages.

Page views are what attribution runs on — keep that one enabled. The others are useful for behaviour analysis and can be toggled any time.

2. Add it to your site

Save the script and open Install instructions from its row. The dialog shows your script id already filled in.

Script tag

Copy this into the <head> of every page:

<script
  src="https://cdn.clakta.com/script.js"
  data-id="YOUR_SCRIPT_ID"
  data-auto-init
  defer
></script>

data-auto-init starts tracking as soon as the script loads. Drop that attribute if you would rather start it yourself — the library then stays inert until you call clakta.init({ id: "YOUR_SCRIPT_ID" }), which is what you want if you gate tracking behind a consent banner.

Next.js

Install the SDK:

npm install @clakta/nextjs

Then render the provider once in your root layout:

import { ClaktaProvider } from "@clakta/nextjs"

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <ClaktaProvider id="YOUR_SCRIPT_ID" />
        {children}
      </body>
    </html>
  )
}

<ClaktaProvider> renders nothing and initializes exactly once per page lifetime. Props passed after the first mount are ignored, so pass the id directly rather than through state that resolves later.

React or plain JavaScript

Install the core package:

npm install @clakta/javascript
import clakta from "@clakta/javascript"

clakta.init({ id: "YOUR_SCRIPT_ID" })

init also accepts debug: true for verbose console logging while you are setting things up, and consent for consent management.

3. Confirm it loads

The install dialog has a Test your website button. Enter one of your domains and Clakta will fetch the page and look for the tag. A green result means the script is present and reachable on that domain.

That check only proves the tag is on the page. To confirm events are actually arriving and attribution is wired up, continue to Verify your setup.

Common mistakes

Next step

Verify your setup — confirm events, orders and ad clicks are all landing where they should.

Related articles