MethodsConsent & Privacy

Consent & Privacy

Control user consent, opt-in/opt-out tracking, and manage privacy settings with the Mythic Analytics SDK.

opt_in() / opt_out()

Control whether the SDK sends events.

mythic.opt_in();   // Enable tracking
mythic.opt_out();  // Disable tracking, clear stored data, discard queued events

opt_out() clears all persisted identity/session data and discards any queued events, in addition to stopping future capture.

has_opted_out()

Check the current opt-out status.

if (mythic.has_opted_out()) {
  showConsentBanner();
}

grantConsent() / revokeConsent()

For consent-gated setups where requireConsent: true. No events are sent until grantConsent() is called.

// User accepts analytics in your cookie banner
function onConsentAccepted() {
  mythic.grantConsent();
}

// User withdraws consent — clears all stored data
function onConsentDeclined() {
  mythic.revokeConsent();
}

When requireConsent is true, the SDK initializes but does not track any events until grantConsent() is called. revokeConsent() stops tracking and clears all local storage.

Set autoConsentMode: true to have the SDK automatically grant or revoke consent based on Google Consent Mode v2 signals pushed to the dataLayer. Enabling it forces requireConsent: true, so tracking stays paused until consent is granted.

window.mythic.init("pk_your_publishable_key", {
  autoConsentMode: true,
  // Or customize which signal to watch:
  // autoConsentMode: { enabled: true, consentParam: "analytics_storage", dataLayerName: "dataLayer" },
});

When the watched consent parameter (default analytics_storage) is granted, the SDK calls grantConsent(); when it is denied, it calls revokeConsent().