MethodsUtility Methods

Utility Methods

Access device, session, and configuration state with the Mythic Analytics SDK utility methods.

Utility methods

getDistinctId()

Returns the current distinct ID (anonymous or identified).

const distinctId = mythic.getDistinctId();

getSessionId()

Returns the current session ID.

const sessionId = mythic.getSessionId();

getDeviceId()

Returns the persistent device ID (5-year expiration).

const deviceId = mythic.getDeviceId();

isBot()

Returns true if the current user agent is detected as a bot.

if (mythic.isBot()) return; // Skip tracking for bots

getPageContext()

Returns the page context extracted by the framework extractor (route name, funnel/page IDs, etc.), or undefined if auto_framework_extract is disabled or no framework was detected.

const ctx = mythic.getPageContext();
// e.g. { $framework: 'nuxt', $route_path: '/products/123', funnel_id: '...' }

getExperimentAssignments()

Returns this visitor's detected A/B test assignments, or []. Empty means one of: no testing tool on the page, capture_experiments disabled, or the tool has not bucketed yet — it runs after the SDK on a normal page load, so poll briefly if you are checking by hand.

mythic.getExperimentAssignments();
// [{ platform: 'convert', experimentId: '1004208131',
//    variationId: '1004489003', variationName: 'Homepage — short form' }]

debug(enabled?)

Toggle debug logging. When enabled, the SDK logs queued events, network requests, and configuration decisions to the console.

mythic.debug(true);  // Enable verbose logging
mythic.debug(false); // Disable

getConfig()

Returns the current SDK configuration object.

const config = mythic.getConfig();
console.log(config.api_host);

updateConfig(newConfig)

Dynamically update configuration options at runtime.

mythic.updateConfig({ debug: true, batch_size: 5 });

refreshConfig()

Re-fetch remote configuration from the server.

await mythic.refreshConfig();