Skip to main content
IntegrationScripts

Tracking Scripts

Inject custom JavaScript, tag managers, and analytics scripts into your learning instance. Access learner context via window.TI and subscribe to learning lifecycle events.

Tag Managers

Inject GTM, Segment, or any tag manager via Panorama tracking scripts.

Console Data

Access window.TI for real-time learner and course context on every page.

Event Listeners

Subscribe to lifecycle events like course completions and quiz submissions.

Google Tag Manager Setup

Add the GTM snippet to your instance via Panorama → Tracking Scripts. Use the {{cspNonce}} placeholder for CSP compliance.

<!-- Google Tag Manager -->
<script nonce="{{cspNonce}}">
  (function(w,d,s,l,i){
    w[l]=w[l]||[];
    w[l].push({'gtm.start': new Date().getTime(), event:'gtm.js'});
    var f=d.getElementsByTagName(s)[0],
        j=d.createElement(s), dl=l!='dataLayer'?'&l='+l:'';
    j.async=true;
    j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;
    f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-XXXXXXX');
</script>

The window.TI Object

Available on every page, this global object provides authenticated user context, current course data, and instance metadata.

// Available on every page in your Thought Industries instance
window.TI = {
  currentUser: {
    id: "usr_12345",
    email: "[email protected]",
    firstName: "Jane",
    lastName: "Doe",
    externalCustomerId: "ext_001",
    role: "learner"
  },
  currentCourse: {
    id: "crs_67890",
    title: "API Fundamentals",
    slug: "api-fundamentals",
    progress: 0.45,
    enrolled: true
  },
  instance: {
    name: "Acme Academy",
    domain: "academy.acme.com"
  }
}

Available Events

EventDescription
ti:course:startedFired when a learner begins a course for the first time.
ti:course:completedFired when a learner completes all required course content.
ti:quiz:completedFired when a learner submits a quiz with results.
ti:page:viewedFired on each content page navigation within a course.
ti:certificate:earnedFired when a certificate is generated for the learner.
ti:enrollment:createdFired when a learner is enrolled in new content.

Event Tracking Example

// Track course completion
document.addEventListener('ti:course:completed', (event) => {
  const { courseId, courseTitle, userId, score } = event.detail;
  
  // Google Analytics 4
  gtag('event', 'course_completed', {
    course_id: courseId,
    course_title: courseTitle,
    score: score
  });
  
  // Segment
  analytics.track('Course Completed', event.detail);
  
  // Custom data layer
  window.dataLayer.push({
    event: 'ti_course_completed',
    ...event.detail
  });
});

Custom Script Injection

Add any custom JavaScript via Panorama → Tracking Scripts. Scripts execute on every page load.

<!-- Injected via Panorama > Tracking Scripts -->
<script nonce="{{cspNonce}}">
  // Fire on every page load
  (function() {
    var user = window.TI?.currentUser;
    if (user) {
      // Identify user in your analytics tool
      myAnalytics.identify(user.id, {
        email: user.email,
        name: user.firstName + ' ' + user.lastName
      });
    }
  })();
</script>

Related Resources