Install the tracking script

Add one script tag to plain HTML, WordPress, Webflow, Next.js, Google Tag Manager, Framer, Ghost, or Shopify.

Dodolytics counts visits with one small script. You add it once to your website, and it works on every page that has it. It does not set cookies.

Your script

Open your website in Dodolytics, then go to Settings › Installation. Click Copy. The script looks like this, with your own website ID:

<script defer src="https://dodolytics.com/tracker.js" data-website-id="site_xxxxxxxxxxxxxxxx"></script>

Use the script from your own Settings page. The ID above is only an example, and it does not work.

Put the script in the <head> of every page, just before </head>. Find your platform below.

Plain HTML

  1. Open the HTML file of each page.
  2. Paste the script just before </head>.
  3. Upload the files to your server.

If your pages share a header file or a template, paste the script there one time. Then every page gets it.

WordPress

We recommend a plugin, because a theme update can remove changes in the theme files.

  1. In WordPress, go to Plugins › Add New.
  2. Find and install a plugin that adds code to the header, for example WPCode. Activate it.
  3. Open the plugin's header and footer page. In WPCode, this is Code Snippets › Header & Footer.
  4. Paste the script in the Header box and save.

Without a plugin: paste the script just before </head> in the header.php file of a child theme.

Webflow

  1. Open your project and go to Site settings › Custom code.
  2. Paste the script in the Head code box.
  3. Click Save, then Publish your site.

Webflow can need a paid plan for custom code. If you cannot edit the Head code box, check your Webflow plan.

Next.js

Add the script to your root layout with the next/script component. For the App Router, this is app/layout.tsx (or app/layout.js):

import Script from 'next/script';

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://dodolytics.com/tracker.js"
          data-website-id="site_xxxxxxxxxxxxxxxx"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

For the Pages Router, put the same <Script> in pages/_app.js.

Single-page apps: in Next.js, React, Vue, and other single-page apps, a click on an internal link changes the page without a new load. The script records each of these page changes too, and the back button. You do not have to add code for this. A change of only the part after ? or # (for example a filter or a tab) is not counted as a new page. For an app with hash routing (/#/pricing), add data-hash="true" to the script. See Tracking script options.

Google Tag Manager

Tag Manager can remove data- attributes from a script tag. So this tag makes the script with JavaScript, which keeps the website ID.

  1. In Tag Manager, open your container and click Tags › New.
  2. Choose the tag type Custom HTML.
  3. Paste this code. Change the website ID to your own.
<script>
  (function () {
    var s = document.createElement('script');
    s.src = 'https://dodolytics.com/tracker.js';
    s.defer = true;
    s.setAttribute('data-website-id', 'site_xxxxxxxxxxxxxxxx');
    document.head.appendChild(s);
  })();
</script>
  1. Under Triggering, choose All Pages.
  2. Save the tag, then click Submit and Publish.

Do not add a History Change trigger to this tag. The script already records the page changes of a single-page app. A second copy of the script counts each page two times.

To add a script option, add one more setAttribute line, for example s.setAttribute('data-scroll', 'true');.

Framer

  1. Open your project and go to Site Settings.
  2. Find the Custom Code section.
  3. Paste the script in the box for the End of <head> tag.
  4. Save, then Publish your site.

Framer runs custom code only on the published site, not in the editor or the preview. Check that tracking works on the published address.

Ghost

  1. In Ghost Admin, go to Settings › Code injection. In newer versions of Ghost, it is in the Advanced section.
  2. Open the Site header box and paste the script.
  3. Click Save.

Only the owner and administrators of a Ghost site can change code injection.

Shopify

  1. In Shopify admin, go to Online Store › Themes.
  2. On your current theme, click the … button, then Edit code.
  3. In the Layout folder, open theme.liquid.
  4. Paste the script just before </head> and click Save.

The script runs on the pages of your theme. Shopify's checkout pages do not use theme.liquid, so they are not tracked.

Other platforms

Most website builders have a setting for "custom code", "header code", or "code injection". Paste the script there, in the head section, for the full site.

If your site has a Content Security Policy, it must allow the script. See Content Security Policy.

After you install it

Open your website in a browser, then check that tracking works.

Related articles

Still need help? Ask on our feedback board or see all topics.