Skip to content

Commit

Permalink
Trigger chameleon survey on down votes (#31241)
Browse files Browse the repository at this point in the history
  • Loading branch information
timroes authored Oct 10, 2023
1 parent ae2ca40 commit 693015e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docusaurus/src/theme/TOCItems/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ import { faThumbsDown, faThumbsUp } from '@fortawesome/free-regular-svg-icons';

import styles from "./TOCItemsWrapper.module.css";

function showDocSurvey() {
const showSurvey = () => {
chmln.show("6525a7ef3f4f150011627c9f");
}

if (!window.chmln) {
// Initialize Chameleon if it's not loaded already
!function(d,w){var t="SaG54hxuMI4CDIZa2yBv4lX1NHVB0jQBNTORqyAN2p2tE4-1OtIxC-DS9ywbXXIr2TPyYr",c="chmln",i=d.createElement("script");if(w[c]||(w[c]={}),!w[c].root){w[c].accountToken=t,w[c].location=w.location.href.toString(),w[c].now=new Date,w[c].fastUrl='https://fast.chameleon.io/';var m="identify alias track clear set show on off custom help _data".split(" ");for(var s=0;s<m.length;s++){!function(){var t=w[c][m[s]+"_a"]=[];w[c][m[s]]=function(){t.push(arguments);};}();}i.src=w[c].fastUrl+"messo/"+t+"/messo.min.js",i.async=!0,d.head.appendChild(i);}}(document,window);
// As soon as it's loaded show the survey
window.chmln.on("load:chmln", showSurvey);
// Identify the user reusing the segment id if possible
window.chmln.identify(window.analytics?.user().id() ?? window.analytics?.user().anonymousId() ?? "chmln-no-segment-user", {});
} else {
showSurvey();
}
}

export default function TOCItemsWrapper(props) {
const [voted, setVoted] = useState(false);
const onVote = (vote) => {
Expand All @@ -15,6 +32,9 @@ export default function TOCItemsWrapper(props) {
vote,
});
setVoted(true);
if (vote === "down") {
showDocSurvey();
}
};
return (
<>
Expand Down

0 comments on commit 693015e

Please sign in to comment.