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
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>2Fire it on every page
Under Triggering, use Initialization - All Pages (or All Pages). In Advanced Settings → Tag firing options, keep Once per page.
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.
<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:
<script>
window.analytics && window.analytics.pageview();
</script>Check that it works
- Open the published site in a normal window, with no ad blocker.
- In your browser devtools, Network tab, filter by
v1/i: you should see aPOSTwith status200within 3 seconds (or when you leave the page). - In the dashboard, events show up in about 30 seconds.
- 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
replaceStateright 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 withoutwww, plus test addresses likehttp://localhost:3000if 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