Skip to content

Use newer TestTrack APIs#98

Merged
rzane merged 30 commits intomainfrom
rzane/use-v4-apis
Jan 21, 2026
Merged

Use newer TestTrack APIs#98
rzane merged 30 commits intomainfrom
rzane/use-v4-apis

Conversation

@rzane
Copy link
Copy Markdown
Contributor

@rzane rzane commented Jan 13, 2026

This PR migrates from TestTrack's v1 APIs to the v4 APIs, which require app versioning information. This allows TestTrack to serve split configurations specific to each build of your application.

load

Fetches visitor config from the server to create a TestTrack instance.

import { load, createCookieStorage } from '@betterment-oss/test-track';

const testTrack = await load({
  client: {
    url: 'https://testtrack.example.com',
    appName: 'my-app',
    appVersion: '0.0.0',
    buildTimestamp: import.meta.env.TT_BUILD_TIMESTAMP
  },
  storage: createCookieStorage({ name: 'tt_visitor_id', domain: '.example.com' })
});

create

Creates a TestTrack instance with preloaded data (e.g., server-rendered).

import { create, createCookieStorage } from '@betterment-oss/test-track';

const testTrack = create({
  client: {
    url: 'https://testtrack.example.com',
    appName: 'my-app',
    appVersion: '0.0.0',
    buildTimestamp: import.meta.env.TT_BUILD_TIMESTAMP
  },
  storage: createCookieStorage({ name: 'tt_visitor_id', domain: '.example.com' }),
  visitorConfig: { visitor: { id: '...', assignments: [...] }, splits: [...] }
});

initialize (Deprecated)

Uses window.TT for configuration. Use load or create instead.

import { initialize } from '@betterment-oss/test-track';

const testTrack = initialize({
  client: {
    appName: 'my-app',
    appVersion: '0.0.0',
    buildTimestamp: import.meta.env.TT_BUILD_TIMESTAMP
  }
});

Breaking changes:

  • Now requires a client option with appName, appVersion, and buildTimestamp
  • Now synchronous (returns TestTrack instead of Promise<TestTrack>)

API Endpoints

  • GET /api/v4/apps/:app/versions/:version/builds/:build/visitors/:id/config replaces GET /api/v1/visitors/:id
  • POST /api/v4/apps/:app/versions/:version/builds/:build/identifier replaces POST /api/v1/identifier
  • POST /api/v2/visitors/:id/assignment_overrides replaces POST /api/v1/assignment_override
  • Request bodies are now JSON instead of form-encoded. This means POST requests to the Test Track API will run a preflight request. See: Relax CORS allowed headers testtrack-cli#69.

Type Changes

  • logIn and signUp now accept value as a string instead of number

Vite Plugin

Provides import.meta.env.TT_BUILD_TIMESTAMP.

import { testTrackPlugin } from '@betterment-oss/test-track/vite';

export default defineConfig({
  plugins: [testTrackPlugin()]
});

@rzane rzane changed the title chore: Use newer TestTrack APIs Use newer TestTrack APIs Jan 13, 2026
@rzane rzane force-pushed the rzane/use-v4-apis branch 6 times, most recently from 625efd5 to bb14df5 Compare January 15, 2026 17:49
Base automatically changed from rzane/analytics to main January 16, 2026 19:24
@rzane rzane force-pushed the rzane/use-v4-apis branch from 568b4ce to a72c990 Compare January 16, 2026 19:27
@rzane rzane marked this pull request as ready for review January 16, 2026 19:27
@rzane rzane requested a review from samandmoore January 16, 2026 19:28
@rzane rzane force-pushed the rzane/use-v4-apis branch from fd33fa2 to 0595c28 Compare January 16, 2026 20:28
@rzane rzane force-pushed the rzane/use-v4-apis branch from 0595c28 to 7dad1a1 Compare January 16, 2026 20:37
Copy link
Copy Markdown
Member

@samandmoore samandmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

domainlgtm

Copy link
Copy Markdown
Member

@samandmoore samandmoore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platformlgtm too

sorry it took me a while to review this!

@rzane rzane merged commit 0f7eca5 into main Jan 21, 2026
5 checks passed
@rzane rzane deleted the rzane/use-v4-apis branch January 21, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants