OnyxMetric
Integration Guides

Ember

Add OnyxMetric analytics to your Ember app

An Ember app renders every route into a single HTML file. Apps from the current Vite-based ember new blueprint keep it at index.html in the project root; classic ember-cli apps use app/index.html.

Copy your tracking snippet

In OnyxMetric, open your site's Site Settings and copy the tracking script. It looks like this:

<script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

YOUR_SITE_ID is the numeric ID of your site.

Add the snippet to Ember

Add the tag inside <head>, after the {{content-for "head"}} placeholder:

index.html
<head>
  <meta charset="utf-8">
  <title>MyApp</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">

  {{content-for "head"}}

  <script src="https://app.onyxmetric.com/api/script.js?siteId=YOUR_SITE_ID" async></script>

  {{content-for "head-footer"}}
</head>

Leave every {{content-for}} placeholder where it is, because the build fills them in. Ember router transitions with the default history location are tracked as pageviews automatically.

Check that it works

Load your live site and click through a few pages. Pageviews show up in the OnyxMetric dashboard within seconds.

If nothing arrives:

  • View the page source and search for script.js?siteId= to confirm the tag is present.
  • In the browser's Network tab, check that script.js returns 200 and that requests go to /api/track.
  • Turn off ad blockers, or proxy the script through your own domain.
  • Read script troubleshooting for other causes.

Track custom events

Call window.onyx.event() from a component action. Use optional chaining so a blocked script does not throw.

app/components/signup-button.gjs
export default class SignupButton extends Component {
  trackSignup = () => {
    window.onyx?.event("signup_click", { location: "hero" });
  };

  <template>
    <button type="button" {{on "click" this.trackSignup}}>Sign up</button>
  </template>
}

Troubleshooting

  • Test runner: tests/index.html is a separate file. Do not add the tag there, or test runs will report pageviews to your dashboard.

Next steps

On this page