JavaScript frameworks
Add Loogika to Ember
You add Loogika to an Ember app by pasting one script tag into the head of the app's index.html. Every Ember route renders into that single HTML file, so one load of the script serves the entire app.
Last updated .
What do you need before you start?
Copy your script tag from Site Settings in the Loogika dashboard, under the Tracking Script tab. It contains your site ID, a 12-character string, where this example says YOUR_SITE_ID:
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
Which file holds the HTML of an Ember app?
The location depends on how the app was created. An app from the current ember new blueprint, which is based on Vite, has the file at index.html in the root of the project. In a classic ember-cli app the path is app/index.html.
How do you add the Loogika script to Ember?
Open the HTML file and paste the tag inside the head element, after the {{content-for "head"}} placeholder:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MyApp</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
<script src="https://app.loogika.com/api/script.js?siteId=YOUR_SITE_ID" defer></script>
{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}
...
{{content-for "body-footer"}}
</body>
</html>
Leave every {{content-for}} placeholder where it is. The Ember build fills those placeholders in with its own tags, so the Loogika tag sits beside them and replaces none of them.
Does Loogika track Ember route transitions?
Yes. Loogika records a pageview for each transition made by the Ember router with the default history location type. You add no code for it.
Route tracking depends on SPA Navigation in Site Settings, which is on for a new site. The Loogika script waits 500 milliseconds after a transition before it records the pageview, so a redirect between routes counts once.
How do you track custom events in Ember?
A component action can send an event with window.loogika.event(). Check that window.loogika exists first. The script may be blocked or still loading, and a call on a missing object throws an error.
import Component from "@glimmer/component";
import { on } from "@ember/modifier";
export default class SignupButton extends Component {
trackSignup = () => {
if (window.loogika) {
window.loogika.event("signup_click", { location: "hero" });
}
};
<template>
<button type="button" {{on "click" this.trackSignup}}>Sign up</button>
</template>
}
The example above is a .gjs component saved as app/components/signup-button.gjs. For a click that needs no logic, add data-loogika-event="signup_click" to the button and leave the action out. The event tracking page explains properties and limits.
How do you check that Loogika is installed?
Open the deployed Ember app in a new tab and move between a few routes. The pageviews appear in the Loogika dashboard within a few seconds.
If nothing arrives, open the page source and look for script.js?siteId=. Then open the Network tab of the browser. The file script.js should return status 200, and POST requests should go to /api/track.
Should you add the tag to tests/index.html?
No. The file tests/index.html is a separate file that the Ember test runner uses. A Loogika tag in that file makes every test run send pageviews to your dashboard.