@indiebob/tracker

v0.5.0

The analytics script for IndieBob: page views, traffic sources, events, signups and revenue. About 5.9 KB gzipped, no dependencies, no cookies. By default it stores nothing in the visitor's browser.

Install

Script tag — one line before </head>. It counts every page, including navigation in a single-page app.

<script src="https://assets.indiebob.com/tracker/v0.5.0/indiebob.min.js" integrity="sha384-eVMAWQwtt75Stu8u3GT3WjsPRzzKYX9YODamOu2W8sH0QbEJrUf0QasXJZNc7thD" crossorigin="anonymous" data-project="proj_…" defer></script>
data-projectYour project id (IndieBob › your project › Connect). Required.
data-persistence="local"Full attribution (see below). Only with the visitor's consent.
data-remember-choices="true"Keep optOut() and ?ib_ignore=1 across pages in privacy mode. Reads two keys on every page: see The visitor's device.
data-hash-mode="true"Your routes live after a # (/#/pricing).
data-auto-page="false"Start the tracker but count pages yourself.
data-api="…"Send to another endpoint.

npm

npm install @indiebob/tracker
import { IndieBob } from '@indiebob/tracker'

const bob = IndieBob.init({ projectId: 'proj_…' })
bob.page()

Privacy mode and full attribution

Privacy mode (default)Full attribution
Stored in the visitor's browsernothinga visitor id, a session id, the first and last UTM, the first referrer
A visitor is recognisedfor one dayacross days
A signup is credited to a visit on an earlier daynoyes
Needs the visitor's consent in the EUnoyes

In privacy mode IndieBob's server identifies a visitor by hashing a random daily salt together with the project, the IP address and the user agent. Each day's salt is deleted, and the IP address is not stored.

Full attribution stores an id on the visitor's device, which needs consent in the EU (ePrivacy Directive, Art. 5(3); localStorage counts the same as a cookie). Switch it on from your consent banner:

bob.setPersistence('local')  // the visitor accepted
bob.setPersistence('none')   // consent withdrawn: removes everything the tracker stored

If consent is already known when the page loads, pass persistence: 'local' to init() or put data-persistence="local" on the tag.

Configuration

IndieBob.init({
  projectId: 'proj_…',        // required
  persistence: 'none',        // 'none' (privacy mode) | 'local' (full attribution)
  rememberChoices: false,     // keep optOut() and ib_ignore across pages (reads two keys)
  autoDetect: true,           // automatic events, below; false turns them off
  hashMode: false,            // routes after a #
  respectDnt: true,           // send nothing when Do Not Track is on
  respectGpc: true,           // send nothing when Global Privacy Control is on
  endpoint: 'https://www.indiebob.com/api/collect',
  debug: false,               // log every event to the console
})

A misspelled or unknown option logs a warning instead of being silently ignored.

API

IndieBob.init(config)Starts the tracker and returns it. Called again for the same project, it returns the running one.
bob.page(overrides?)Counts a page view. The same path twice in a row counts once. overrides: { path, title, referrer }.
bob.track(name, properties?)A named event: bob.track('csv_exported', { rows: 1240 }).
bob.identify(userId, traits?, { isNew? })After signup or login. Links the visit to your user id and sends signup or login. Pass isNew: true after a registration and false on a login — in privacy mode it is required for the signup/login event. Use your own id, never an email address, as userId.
bob.revenue({ amount, currency, plan, type })A payment, if Stripe is not connected to IndieBob. type: new, renewal, upgrade, downgrade.
bob.setPersistence('none' | 'local')Switches mode, above.
bob.enableAutoPage()Counts a page on every history change (the script tag does this itself).
bob.optOut(), bob.optIn(), bob.isOptedOut()The visitor's own opt-out; optOut() removes everything stored. In privacy mode it lasts until the page is left, unless you use rememberChoices.
bob.isIgnored()Whether this browser is excluded with ?ib_ignore=1.
bob.flush()Sends queued events now.

Events are sent in batches every 5 seconds and when the page is hidden or closed.

Collected automatically

pageEvery page view, including a page restored with the Back button.
engagementWhen a page is left or hidden: how long it was visible and focused, and how far it was scrolled.
outbound_clickA link to another site is clicked.
file_downloadA link to a file (pdf, zip, dmg, exe, apk, …) is clicked.
signup_start, login_view, pricing_view, checkout_view, success_view, onboarding_view, contact_viewThe page's path matches /signup, /login, /pricing, … or their Spanish, French, German, Portuguese, Italian or Dutch words.
signup_submit, login_submit, checkout_submitA form is submitted on one of those pages.
any nameAn element with data-ib-event="name" is clicked; its other data-ib-* attributes become properties.

Turn parts off or replace the path patterns:

autoDetect: { fileDownloads: false, outboundClicks: false, formSubmit: false, dataAttributes: false,
              signupPaths: [/\/start-trial/] }

What is sent

  • The page's path and URL, keeping only the utm_* and ref query parameters. Anything else in a query string — sign-in tokens, reset codes, email addresses, ad click ids — is removed before it leaves the page, and IndieBob's server removes it again from older versions of the tracker.
  • The page title; the referrer's origin and path; the screen size class; the browser's language and time zone; your event's properties.
  • IndieBob adds the country, region and city (looked up from the IP address, which is not stored), the browser, the operating system and the device type.

Nothing is sent from a browser with Do Not Track or Global Privacy Control on, after optOut(), from automated browsers, or on a page opened with ?ib_ignore=1.

The visitor's device

In privacy mode the tracker makes no storage calls at all: it neither reads nor writes localStorage or sessionStorage, on load, on a page view, on an event or on leaving. Do Not Track and Global Privacy Control are checked first, and with either on storage is not touched in any mode. Requests carry no credentials, and the tag above uses crossorigin="anonymous", so the cookie of the CDN in front of IndieBob (__cf_bm) is not stored either. A tag without crossorigin does store it.

So optOut() and ?ib_ignore=1 last until the page is left, and ?ib_ignore=0 has nothing to undo. If your consent tool already keeps the visitor's choice, call bob.optOut() from it on each page. To have the tracker remember both instead, add data-remember-choices="true" or rememberChoices: true: it then reads two keys, _ib_optout and ib_ignore, on every page, after Do Not Track and Global Privacy Control, and writes one only when the person makes that choice. ePrivacy Art. 5(3) covers reading as well as storing, so decide this with your own legal basis in mind.

IndieBob processes this data for you, in the EU (Frankfurt), under its data processing agreement.

Vue and Nuxt

// plugins/indiebob.client.ts (Nuxt) — or app.use(...) after the router in a Vue app
import { IndieBobPlugin } from '@indiebob/tracker/vue'

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.use(IndieBobPlugin, { projectId: 'proj_…' })
})

Page views follow vue-router. In a component: const bob = useTracker() from @indiebob/tracker/vue.

React

There is no React package; call page() when the route changes:

const pathname = usePathname()
useEffect(() => { bob.page() }, [pathname])

Server

For events with no browser — a webhook, a job:

import { IndieBob } from '@indiebob/tracker/server'

const bob = IndieBob.initServer({ projectId: 'proj_…' })
await bob.track('trial_started', { plan: 'pro' }, 'user_123')
await bob.identify('user_123', { plan: 'pro' })

Versions

The tag at the top of this page is pinned to version 0.5.0: a versioned file never changes, and with integrity the browser refuses to run anything else, so a compromised asset host cannot reach your pages. Each release's hash is in the changelog that ships in the package. This one:

sha384-eVMAWQwtt75Stu8u3GT3WjsPRzzKYX9YODamOu2W8sH0QbEJrUf0QasXJZNc7thD

/tracker/latest/indiebob.min.js is always the newest release. Nothing checks it, so you trust the asset host with every page it runs on:

<script src="https://assets.indiebob.com/tracker/latest/indiebob.min.js" crossorigin="anonymous" data-project="proj_…" defer></script>

The npm package follows semver; while it is 0.x, a minor release (0.4 → 0.5) can change behaviour, so read the changelog before upgrading.

Serving your own copy

You can. Copy indiebob.min.js to your own site and load it from there. Nothing depends on the script's address: events still go to https://www.indiebob.com/api/collect, which accepts any origin, and the project id decides where they land. Your visitors then make no request to the asset host at all.

<script src="/js/indiebob.min.js" data-project="proj_…" defer></script>

Turning auto-detection off

The tag cannot turn auto-detection off. Leave data-project off the tag, so it does not start itself, and start it from your own script. Page views still send an engagement event as the page is left (time on the page and how far it was scrolled):

<script src="/js/indiebob.min.js" defer></script>
<script defer>
  addEventListener('DOMContentLoaded', () => {
    const bob = IndieBob.init({ projectId: 'proj_…', autoDetect: false })
    bob.page()
    bob.enableAutoPage()
  })
</script>

Browsers: the script tag needs Chrome 80, Firefox 74 or Safari 13.1 or newer; the npm build targets ES2018. Licence: MIT.