Tracking Snippet

Add the Moonship snippet to your site to start tracking pageviews, sessions, and custom events.

Add the snippet to your site's <head>. You'll find your site-specific snippet on the Sites page — copy it from there to get your real tracking key pre-filled.

<script>window.moonship=window.moonship||{_q:[],track:function(){this._q.push(["track",arguments])},identify:function(){this._q.push(["identify",arguments])}}</script>
<script src="https://moonship.com/v1/events.js?key=YOUR_TRACKING_KEY" async></script>

Replace YOUR_TRACKING_KEY with the key shown on your Sites page. The second line loads events.js asynchronously so it won't block your page — but that means it isn't ready the instant the page runs. The first line is a tiny stub that fills the gap: it defines moonship.track() and moonship.identify() up front so any calls made before events.js finishes loading are queued instead of throwing moonship is undefined. Once the script loads, it replays the queued calls in order, so no early events are lost.

What gets tracked automatically

  • Pageviews — every page load, including the full URL
  • Sessions — grouped by visitor activity within a 30-minute window
  • Referrers & UTM params — where visitors came from
  • Device, browser & OS — desktop, mobile, or tablet, plus browser and operating system
  • Location — country and city (from IP, no cookies required)
  • Call-to-action visibility — when a primary button or link is actually seen on screen, and whether it then gets clicked

Marking calls-to-action

Moonship automatically spots primary calls-to-action — buttons and links like “Get started”, “Sign up”, or “Start free trial” — and records when each one is seen on screen and whether it gets clicked. That's what lets it tell a messaging problem (people see the button but don't click) apart from a traffic problem (fewer people see it at all).

Detection is deliberately conservative. To guarantee a specific element is tracked — or to mark one the heuristics miss — add the data-moonship-cta attribute. Its value is a label you'll recognize in your data:

<a href="/signup" data-moonship-cta="hero-signup">Start free trial</a>

Automatic detection needs no code changes — the attribute is only for adding or overriding a CTA. Visibility tracking uses a modern browser API; where it isn't available it simply does nothing, with no effect on the rest of your tracking.

Custom events

Track any user action by calling moonship.track() after the snippet is on the page:

// Track a goal or conversion event
moonship.track('signup', { plan: 'pro' });

Custom events appear in your Live stream and can be used as Goals for conversion tracking.

On this page