Install GoSquared Tracking Code | OpsBlu Docs

Install GoSquared Tracking Code

Step-by-step instructions for installing GoSquared analytics via direct embed, npm, Google Tag Manager, and SPA frameworks.

Deployment Strategy

GoSquared provides a lightweight JavaScript snippet (~5KB) for real-time analytics, user identification, and live chat. The recommended deployment is direct embed for most sites, or npm for JavaScript frameworks (React, Vue, Next.js).

Direct JavaScript Embed

Add the GoSquared snippet before the closing </body> tag on every page:

<script>
  !function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(arguments)};
  d=s.createElement(q);d.src='//d1l6p2sc9645hc.cloudfront.net/gosquared.js';
  q=s.getElementsByTagName(q)[0];q.parentNode.insertBefore(d,q)}
  (window,document,'script','_gs');

  _gs('GSN-XXXXXX-X');  // Replace with your project token
  _gs('set', 'anonymizeIP', true);  // Recommended for GDPR
</script>

Where to find your project token: GoSquared Dashboard → Settings → Current Site → Tracking Code. The token format is GSN-XXXXXX-X.

Placement matters: Put the snippet at the end of <body>, not in <head>. GoSquared loads asynchronously, so it won't block page rendering, but placing it in <body> ensures the DOM is available for the live chat widget.

npm / Yarn Installation

For JavaScript applications (React, Vue, Angular, Next.js):

npm install gosquared
// Initialize in your app entry point
import GoSquared from 'gosquared';

GoSquared.configure({
  site_token: 'GSN-XXXXXX-X',
  anonymize_ip: true
});

// Track page views (automatic for static sites,
// manual for SPAs — see SPA section below)

Google Tag Manager

  1. In GTM, go to Tags → New → Custom HTML.
  2. Paste the JavaScript snippet above (without the <script> tags — GTM wraps it automatically).
  3. Set the trigger to All Pages (or specific page groups if you want selective tracking).
  4. Use GTM Preview mode to verify the tag fires and _gs is available in the console.
  5. Publish the container.

GTM variables for multi-environment setup: Create a GTM Lookup Table variable that returns different project tokens based on {{Page Hostname}} — this prevents staging data from mixing with production.

SPA Framework Integration

GoSquared doesn't automatically detect client-side route changes. You must call _gs('track') on each navigation.

React (React Router)

import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

function App() {
  const location = useLocation();

  useEffect(() => {
    if (typeof _gs === 'function') {
      _gs('track', location.pathname, document.title);
    }
  }, [location]);

  return <Routes>{/* ... */}</Routes>;
}

Vue (Vue Router)

// In your router/index.js
router.afterEach((to) => {
  if (typeof _gs === 'function') {
    _gs('track', to.path, to.meta.title || document.title);
  }
});

Next.js (App Router)

// components/GoSquaredTracker.tsx
'use client';
import { usePathname } from 'next/navigation';
import { useEffect } from 'react';

export function GoSquaredTracker() {
  const pathname = usePathname();
  useEffect(() => {
    if (typeof _gs === 'function') _gs('track');
  }, [pathname]);
  return null;
}

// Add <GoSquaredTracker /> to your root layout.tsx

User Identification

Identify logged-in users to connect anonymous browsing sessions to known accounts:

// Call after user authenticates
_gs('identify', {
  id: 'user-12345',           // Required: your internal user ID
  email: 'jane@example.com',  // Enables People CRM features
  name: 'Jane Smith',
  custom: {
    plan: 'Pro',
    company: 'Acme Corp',
    signup_date: '2025-01-15'
  }
});

Timing: Call _gs('identify') after login, not on every page load. GoSquared persists the identity in a cookie, so subsequent page views are automatically associated with the identified user.

// GDPR: Anonymize visitor IP addresses
_gs('set', 'anonymizeIP', true);

// Don't capture URL query parameters (strips PII from URLs)
_gs('set', 'trackParams', false);

// Consent-gated loading: don't load GoSquared until consent given
// In your CMP callback (OneTrust, Cookiebot, etc.):
function onAnalyticsConsent() {
  // Dynamically load the GoSquared snippet here
  var d = document.createElement('script');
  d.src = '//d1l6p2sc9645hc.cloudfront.net/gosquared.js';
  document.body.appendChild(d);
  d.onload = function() {
    _gs('GSN-XXXXXX-X');
    _gs('set', 'anonymizeIP', true);
  };
}

Verification

After installing, verify GoSquared is working:

// 1. Open browser console on your site
console.log(typeof _gs);
// Expected: 'function' — if 'undefined', the snippet didn't load

// 2. Enable debug mode to see outbound tracking requests
_gs('debug', true);
// Console will log every event sent to GoSquared

// 3. Check the GoSquared dashboard
// Real-time → Now → your visit should appear within seconds

If verification fails: See the Troubleshooting guide for common installation issues including CSP blocks, ad blocker interference, and async loading race conditions.