Install target
One v1 widget script in the app shell
Install AnswerLattice
Vue and Nuxt guidance for installing the v1 widget and updating context on route changes.
One v1 widget script in the app shell
Path, title, feature, workflow, role, locale
Loaded, origin allowed, route allowed, context received
Install verification
Script, allowed origin, blocked route, safe context, and fallback checks are visible before product users rely on support.
Add the v1 widget script and safe context adapter.
Verify origin, route, context, and fallback readiness.
Go live only after the runtime checks pass.
import { onMounted, onUnmounted, watch } from 'vue';
import { useRoute } from 'vue-router';
export function useAnswerlatticeInstall(widgetKey: string) {
const route = useRoute();
let removeLoadListener = () => {};
const updateContext = () => {
if (!widgetKey) return;
window.AnswerlatticeWidget?.page({
path: route.path,
title: document.title,
feature: route.path.split('/').filter(Boolean)[0] || 'app',
role: 'member',
locale: navigator.language || 'en',
});
};
onMounted(() => {
if (!widgetKey) return;
let script = document.querySelector<HTMLScriptElement>('script[data-answerlattice-widget="v1"]');
if (!script) {
script = document.createElement('script');
script.src = 'https://answerlattice.com/widget/v1/answerlattice-widget.js';
script.async = true;
script.setAttribute('data-answerlattice-widget', 'v1');
script.setAttribute('data-answerlattice-key', widgetKey);
document.head.appendChild(script);
}
if (!window.AnswerlatticeWidget) {
script.addEventListener('load', updateContext, { once: true });
removeLoadListener = () => script.removeEventListener('load', updateContext);
}
updateContext();
});
onUnmounted(() => removeLoadListener());
watch(() => route.path, updateContext);
}