Skip to content

Commit

Permalink
feat: trigger survey monkey on chat close
Browse files Browse the repository at this point in the history
  • Loading branch information
alangsto committed Jul 1, 2024
1 parent 2fb1862 commit 8972653
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import './Sidebar.scss';
import {
clearMessages,
} from '../../data/thunks';
import { PROMPT_EXPERIMENT_FLAG } from '../../constants/experiments';
import { PROMPT_EXPERIMENT_FLAG, PROMPT_EXPERIMENT_KEY } from '../../constants/experiments';
import { showControlSurvey, showVariationSurvey } from '../../utils/surveyMonkey';

const Sidebar = ({
courseId,
Expand Down Expand Up @@ -71,10 +72,12 @@ const Sidebar = ({
const handleClick = () => {
setIsOpen(false);

// check to see if hotjar is available, then trigger hotjar event if user has sent and received a message
const hasWindow = typeof window !== 'undefined';
if (hasWindow && window.hj && messageList.length >= 2) {
window.hj('event', 'ocm_learning_assistant_chat_closed');
if (messageList.length >= 2) {
if (variationKey === PROMPT_EXPERIMENT_KEY) {
showVariationSurvey();
} else {
showControlSurvey();
}
}
};

Expand Down
17 changes: 17 additions & 0 deletions src/utils/surveyMonkey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* eslint-disable func-names,no-unused-expressions,no-param-reassign,no-sequences */

// This function contains the script provided by SuveryMonkey,
// which is used to embed the survey in the html upon this function
// being called after a learner closes the chat window for the control group.
const showControlSurvey = () => {
(function (t, e, s, o) { let n; let c; let l; t.SMCX = t.SMCX || [], e.getElementById(o) || (n = e.getElementsByTagName(s), c = n[n.length - 1], l = e.createElement(s), l.type = 'text/javascript', l.async = !0, l.id = o, l.src = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd30kMLlLtc4okiu60NJiBPZxbfwe_2FCDOk5JO3Imfyeqk.js', c.parentNode.insertBefore(l, c)); }(window, document, 'script', 'smcx-sdk'));
};

const showVariationSurvey = () => {
(function (t, e, s, o) { let n; let c; let l; t.SMCX = t.SMCX || [], e.getElementById(o) || (n = e.getElementsByTagName(s), c = n[n.length - 1], l = e.createElement(s), l.type = 'text/javascript', l.async = !0, l.id = o, l.src = 'https://widget.surveymonkey.com/collect/website/js/tRaiETqnLgj758hTBazgd3i4lLmPCzca7_2BgAvTEbjU2dNWmi5l435XUxCEkddDIn.js', c.parentNode.insertBefore(l, c)); }(window, document, 'script', 'smcx-sdk'));
}

Check failure on line 12 in src/utils/surveyMonkey.js

View workflow job for this annotation

GitHub Actions / test

Missing semicolon

export {
showControlSurvey,
showVariationSurvey,
};

0 comments on commit 8972653

Please sign in to comment.