Vue quickstart

1. Install hypertune

Once you have a Vue application ready, install Hypertune's JavaScript SDK:

npm install hypertune

2. Set environment variables

Define the following environment variables in your .env file:

VITE_HYPERTUNE_TOKEN=token
HYPERTUNE_FRAMEWORK=vue
HYPERTUNE_OUTPUT_DIRECTORY_PATH=src/generated

Replace token with your main project token which you can find in the Settings tab of your project.

3. Generate the client

Generate a type-safe client to access your flags by running:

npx hypertune

4. Use the client

Add the generated hypertunePlugin to your app:

src/main.ts
import { createApp } from "vue";
import { hypertunePlugin } from "./generated/hypertune.vue";
import App from "./App.vue";
import "./style.css";

createApp(App)
  .use(hypertunePlugin, {
    createSourceOptions: {
      token: import.meta.env.VITE_HYPERTUNE_TOKEN!,
    },
    rootArgs: {
      context: {
        environment: "development",
        user: { id: "1", name: "Test", email: "hi@test.com" },
      },
    },
  })
  .mount("#app");

Then use the generated useHypertune composable to access your flags:

src/components/Example.vue
<script setup lang="ts">
import { useHypertune } from '../generated/hypertune.vue';

const hypertune = useHypertune()
</script>

<template>
  <div>
    Example Flag: {{ hypertune.exampleFlag({ fallback: false }) }}
  </div>
</template>

If you have a Content Security Policy, add the following URLs to the connect-src directive: https://edge.hypertune.com https://gcp.fasthorse.workers.dev

This lets the browser send analytics back to Hypertune so you can see how often different parts of your flag logic are evaluated, e.g. to see how many sessions fall into each targeting rule, as well as analytics for your events, A/B tests and machine learning loops.

5. (Optional) Include a build-time logic snapshot

If you try accessing a flag on the first app render, you'll get your hardcoded fallback value if the SDK hasn't initialized from Hypertune Edge yet. This can result in a UI flicker or layout shift if the flag value changes when the SDK initializes.

To avoid this, you can include a snapshot of your flag logic in the generated client at build time. The SDK will instantly initialize from the snapshot first before fetching the latest flag logic from Hypertune Edge.

Add the following environment variable to your .env file:

HYPERTUNE_INCLUDE_INIT_DATA=true

Then regenerate the client.

You can keep the snapshot fresh by setting up a webhook to regenerate the client and redeploy your app on every Hypertune commit. In this case, you don't need to initialize from Hypertune Edge at all.

That's it

Now you can update the logic for exampleFlag from the Hypertune UI without updating your code or waiting for a new build, deployment or app release.

To add a new flag, create it in the Hypertune UI then regenerate the client.

Last updated