Skip to content
DocsInstall the script

Install the script

One deferred script tag per website, in the head of every page. No npm package, plugin or app to install, and no cookies to configure.

Where it goes

Copy your website’s script from Install in the dashboard and paste it once inside <head>, before </head>, on every page. It needs to be in the HTML your server sends, not added later by a tag manager or consent tool, or the installation check can’t find it.

Example script
<script defer
  src="https://getmayfly.com/mayfly.js"
  data-site="YOUR_SITE_ID"
  data-verify="YOUR_VERIFICATION_CODE"></script>

data-site is your site ID. data-verify is a public, one-time verification code; you can leave it in place after the site is verified. Single-page apps need nothing extra: route changes are tracked automatically.

Platform guides

These are the four the Install screen has written steps for. Install the script once only, whichever route you take.

Other site builders, including Framer and Webflow

We haven’t tested Framer or Webflow yet, so there is no guide for them. What any builder needs is a way to put the script in the head of every published page. If yours adds head code only after the page has loaded, the installation check won’t find the script. You can still prove ownership with a DNS record, but visits are counted only if the script actually loads.

Optional settings

Add any of these attributes to the script tag:

AttributeWhat it does
data-outbound="false"Stops recording clicks on links to other sites and on file downloads.
data-vitals="false"Stops collecting Core Web Vitals.
data-hash="true"Counts a change of the URL’s #hash as a new pageview, for sites that route with hashes.
data-local="true"Records visits on localhost, 127.0.0.1 and .local hosts, which are skipped by default.
data-allow="…"A regular expression. Only events whose full page address matches it are sent.

Content Security Policy

If your site sends a Content Security Policy, allow Mayfly’s origin in both script-src and connect-src:

CSP sources to add
script-src https://getmayfly.com;
connect-src https://getmayfly.com;

Leaving out your own visits

The script never runs for browsers that send Do Not Track, and skips localhost. To exclude yourself on a device, run this once in your browser’s console on your site. The flag is read locally and never sent.

Exclude this browser
localStorage.setItem('mayfly_ignore', '1')

Not connecting? Check these first

  • Install on the hostname you added. Its www version works too; a redirect to an unrelated host does not.
  • The verification code must be in the published HTML, not only after a tag manager or consent tool runs.
  • Allow Mayfly’s origin in your CSP, as above.
  • Visits before verification are discarded. Reload your website after the check succeeds.
  • Make sure your firewall lets through the Mayfly-Install-Check user agent. Private, password-protected and localhost sites can’t be checked this way.

Something here doesn’t match what you see? Write to kirylapps@gmail.com.