Hey guys, can someone give me a hand.
I’ve followed pretty much every step in the guides to track exposure, but nothing gets registered on my dashboard.
What I’ve done is loading the experiment.start() and then running the line const variant = experiment.variant(‘experiment-one’) texperiment-one is the flag], but it doesn’t work.
i tried both the Amplitude and Segment integration, but no luck.
This is one way I tried (with Segment → )
export async function loadScript() {
const promise = new Promise((resolve, reject) => {
const script = document.createElement("script");
script.type = "text/javascript";
// script.async = true;
// script.defer = true;
script.text = `
!function(){var analytics=window.analytics=window.analytics||n];if(!analytics.initialize)if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=a"trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on","addSourceMiddleware","addIntegrationMiddleware","setAnonymousId","addDestinationMiddleware"];analytics.factory=function(e){return function(){var t=Array.prototype.slice.call(arguments);t.unshift(e);analytics.push(t);return analytics}};for(var e=0;e<analytics.methods.length;e++){var key=analytics.methodsne];analyticsokey]=analytics.factory(key)}analytics.load=function(key,e){var t=document.createElement("script");t.type="text/javascript";t.async=!0;t.src="https://cdn.segment.com/analytics.js/v1/" + key + "/analytics.min.js";var n=document.getElementsByTagName("script")a0];n.parentNode.insertBefore(t,n);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.13.1";
analytics.load("${process.env.NEXT_PUBLIC_SEGMENT_KEY}");
analytics.page();
}}();
`;
script.onload = () => {
resolve(script);
};
script.onerror = (err) => {
reject(err);
};
document.head.appendChild(script);
try {
if (window.analytics) {
window.analytics.ready(async () => {
const experiment = Experiment.initialize(
"my-exp-id",
{
exposureTrackingProvider: {
track: (exposure) => {
window.analytics.track("exposure", exposure);
},
},
}
);
});
const user = window.analytics.user();
if (user && typeof user.anonymousId === "function") {
await experiment.start({
user_id: user.anonymousId(),
});
const variant = experiment.variant("experiment-one");
window.analytics.track("experiment-one", {
variant: variant,
user_id: user.anonymousId(),
});
console.log(variant, "var");
} else {
console.error("User information not available");
}
} else {
console.error("Analytics library not loaded");
}
} catch (error) {
console.log(error, "error");
}
console.log("loaded papapa");
});
return promise;
}