# `segment`

The `segment` registry script. It loads `https://cdn.segment.com/analytics.js/v1/abcDEF123/analytics.min.js` for the input of the example. Call `useScriptSegment(input, options?)` from `@hamur/scripts/<library>` in a component, or list it under `scripts.registry.segment` to load it on every page.

| | |
|---|---|
| Config key | `scripts.registry.segment` |
| Function | `useScriptSegment` of `@hamur/scripts/<library>` |
| Input keys | `writeKey` (required) |
| Default trigger | `client` |
| Script | `https://cdn.segment.com/analytics.js/v1/abcDEF123/analytics.min.js` |
| Hosts | `cdn.segment.com`, `api.segment.io`, `cdn-settings.segment.com` |
| Bundle | yes: `scripts.bundle: ["segment"]` |
| Collection proxy | no |
| Consent | none |

## Example

````ts [scripts/registry/segment.ts]
import { defineConfig } from "hamur";
import scripts from "@hamur/scripts";

export default defineConfig({
  framework: "react",
  modules: [scripts],
  scripts: {
    registry: {
      segment: { writeKey: "abcDEF123" },
    },
  },
});
````

It loads after the app mounted and the first idle callback. List `segment` in `scripts.bundle` and the build serves the file from your origin with a SHA-384 `integrity` (see [Bundling](/scripts#bundle-a-script-into-your-build)). The script sends its own requests to the vendor.

Every key is checked when the config loads and again in `useScriptSegment`: a wrong value stops the build with a message that starts with `scripts.registry.segment`. The registry list is on the [registry](/scripts/registry) page, and the shared options are in [Scripts](/scripts).
