Skip to content

mixpanel

The mixpanel registry script. It loads https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js for the input of the example. Call useScriptMixpanel(input, options?) from @hamur/scripts/<library> in a component, or list it under scripts.registry.mixpanel to load it on every page.

Config keyscripts.registry.mixpanel
FunctionuseScriptMixpanel of @hamur/scripts/<library>
Input keystoken (required), apiHost
Default triggerclient
Scripthttps://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js
Hostscdn.mxpnl.com, api-js.mixpanel.com
Bundleyes: scripts.bundle: ["mixpanel"]
Collection proxyyes: /_hamur/scripts/p/mixpanel; flags on by default: ip, userAgent, language, screen, timezone, hardware
Consentnone

Example

ts
import { defineConfig } from "hamur";
import scripts from "@hamur/scripts";

export default defineConfig({
  framework: "react",
  modules: [scripts],
  scripts: {
    registry: {
      mixpanel: { token: "0123456789abcdef0123456789abcdef" },
    },
  },
});

It loads after the app mounted and the first idle callback. List mixpanel in scripts.bundle and the build serves the file from your origin with a SHA-384 integrity (see Bundling). With the script bundled, its collection requests go to /_hamur/scripts/p/mixpanel on your origin, which forwards them to https://api-js.mixpanel.com with the privacy flags applied; see The privacy proxy.

Every key is checked when the config loads and again in useScriptMixpanel: a wrong value stops the build with a message that starts with scripts.registry.mixpanel. The registry list is on the registry page, and the shared options are in Scripts.