Developers

Last Updated: February 1st 2023

Tracking Code

We recommend that you install the tracking code within the <head> of your page so that it captures as much of the session as possible. Loading the script just before the <body/> could result in the first second or so of a visitors' session being missed.

The script is very light and loading is non-blocking, so performance should not be a concern.

If you would prefer to defer the loading of Squeaky until the entire page has loaded, you can load the script with defer or async, however you may miss the begninning of the session.

You can find the correct script with your site id on the settings page of your site. Every site is different, but here are some suggestions for where best to place the script into your app.

<!DOCTYPE html>
  <html>
  <head>
    <script>
      (function(s,q,u,e,a,k,y){
        s._sqSettings={site_id:'your-site-id'};
        e=q.getElementsByTagName('head')[0];
        a=q.createElement('script');
        a.src=u+s._sqSettings.site_id;
        e.appendChild(a);
      })(window,document,'https://cdn.squeaky.ai/g/1.1.0/script.js?');
    </script>
  </head>

  <body>
    <%= yield %>
  </body>
</html>
import NextDocument, { 
  Html, 
  Head, 
  Main, 
  NextScript, 
  DocumentContext,
} from 'next/document';

class Document extends NextDocument {
  static async getInitialProps(ctx: DocumentContext) {
    return NextDocument.getInitialProps(ctx);
  }

  public render(): JSX.Element {
    return (
      <Html>
        <Head>
          <script dangerouslySetInnerHTML={{ __html: `
            (function(s,q,u,e,a,k,y){
              s._sqSettings={site_id:'your-site-id'};
              e=q.getElementsByTagName('head')[0];
              a=q.createElement('script');
              a.src=u+s._sqSettings.site_id;
              e.appendChild(a);
            })(window,document,'https://cdn.squeaky.ai/g/1.1.0/script.js?');
          `}} />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      );
    }
  }
}

export default Document;