All integration guides

Integration guide

Analytics via Google Tag Manager

If your site already runs GTM, you can install Analisa without touching code: one Custom HTML tag loads the SDK, and the triggers you already have become events.

Before you start

  • The GTM container installed on your site and permission to publish.
  • Your site_key, and your domain under Allowed origins.

Installation

  1. 1Create the tag that loads the SDK

    Under Tags → New, pick Custom HTML and paste the code below. It waits for the SDK to finish loading before creating the instance — inside GTM, the order of several <script> tags isn’t guaranteed.

    Tag: Custom HTML
    <script>
      (function () {
        var s = document.createElement('script');
        s.src = 'https://cdn.jsdelivr.net/npm/@racoelho/analytics@0.2/dist/index.global.js';
        s.async = true;
        s.onload = function () {
          // create the instance only after the SDK has loaded
          window.analytics = new Analytics.Analytics({ siteKey: 'YOUR_SITE_KEY' });
        };
        document.head.appendChild(s);
      })();
    </script>
  2. 2Fire it on every page

    Under Triggering, use Initialization - All Pages (or All Pages). In Advanced Settings → Tag firing options, keep Once per page.

  3. 3Test and publish

    Click Preview, open your site through Tag Assistant and check the tag fired. Then Submit to publish the container version.

Events and goals

For each conversion, create another Custom HTML tag with the trigger you already use (click, form submission, a custom dataLayer event). GTM variables such as {{Page Path}} can become properties.

Tag: Custom HTML
<script>
  // tag "Analisa – Signup", fired on the button click or form submission
  window.analytics && window.analytics.track('signup', { page: {{Page Path}} });
</script>

In the Analisa dashboard, create the signup event goal. window.analytics && avoids an error if the event tag fires before the SDK has loaded.

Page navigation

In single-page apps, the SDK only counts the first load. Create a tag with the History Change trigger, which fires on pushState, replaceState and fragment changes:

Tag: Custom HTML · Trigger: History Change
<script>
  window.analytics && window.analytics.pageview();
</script>

Check that it works

  1. Open the published site in a normal window, with no ad blocker.
  2. In your browser devtools, Network tab, filter by v1/i: you should see a POST with status 200 within 3 seconds (or when you leave the page).
  3. In the dashboard, events show up in about 30 seconds.
  4. In Preview mode, check that the SDK tag shows under "Tags Fired" on the first page.

Troubleshooting

The tag fires, but nothing arrives
Make sure the container version was published (Preview doesn’t publish). Also check your domain under Allowed origins.
Double pageviews in a SPA
Some routers call replaceState right on load. The SDK drops a repeat of the same path within 2.5 seconds; if it still doubles, add a condition to the trigger (for example, "History Source equals pushState").
The request returns 403 (origin_not_allowed)
Your domain isn’t in Allowed origins in the site settings. Add the exact origin — with https://, with and without www, plus test addresses like http://localhost:3000 if you want to measure in development.
No request shows up in the Network tab
The SDK honors Do Not Track by default: if your browser sends DNT, nothing is sent. Test in another browser or profile. Ad blockers can also block the script.
Pageviews show up twice
The SDK was initialized twice (for example, pasted in the theme and also added by a plugin). Keep a single instance per page.

Create your account and grab the site_key

Free up to 10K events a month, no credit card.

Create a free account
Analytics via Google Tag Manager, without cookies · Analisa