добавлена метрика ВП ЯМ

This commit is contained in:
Nastya 2024-05-06 01:07:15 +03:00
parent fcf4a13cc2
commit a900035409
9 changed files with 302 additions and 136 deletions

@ -43,6 +43,30 @@ function QuizAnswererInner({ quizSettings, quizId, preview = false, changeFavico
refreshInterval: 0, refreshInterval: 0,
}); });
useEffect(() => {
setTimeout(() => {
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && quizSettings?.settings.cfg.yandexMetricNumber !== undefined) {
YM(
quizSettings.settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-start"
);
};
if (VP !== undefined && quizSettings?.settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: quizSettings.settings.cfg.vkMetricNumber,
goal: "penaquiz-start"
});
};
}, 4000)
}, [])
useLayoutEffect(() => { useLayoutEffect(() => {
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth); if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
}, []); }, []);

@ -141,7 +141,25 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}"); const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
sessions[quizId] = Date.now(); sessions[quizId] = Date.now();
localStorage.setItem("sessions", JSON.stringify(sessions)); localStorage.setItem("sessions", JSON.stringify(sessions));
enqueueSnackbar("Данные успешно отправлены");
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-contacts"
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: "penaquiz-contacts"
});
};
} catch (e) { } catch (e) {
enqueueSnackbar("повторите попытку позже"); enqueueSnackbar("повторите попытку позже");
} }
@ -152,6 +170,26 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
setFire(false); setFire(false);
} }
useEffect(() => {
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-form"
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: "penaquiz-form"
});
};
}, [])
return ( return (
<Box <Box
@ -175,8 +213,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
settings.cfg.design && !isMobile settings.cfg.design && !isMobile
? quizThemes[settings.cfg.theme].isLight ? quizThemes[settings.cfg.theme].isLight
? `url(${DESIGN_LIST[settings.cfg.theme]})` ? `url(${DESIGN_LIST[settings.cfg.theme]})`
: `linear-gradient(90deg, #272626, transparent), url(${ : `linear-gradient(90deg, #272626, transparent), url(${DESIGN_LIST[settings.cfg.theme]
DESIGN_LIST[settings.cfg.theme]
})` })`
: null, : null,
}} }}
@ -334,8 +371,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
<Box <Box
component={Link} component={Link}
target={"_blank"} target={"_blank"}
href={`https://${ href={`https://${window.location.hostname.includes("s") ? "s" : ""
window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`} }quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{ sx={{
display: "flex", display: "flex",

@ -35,7 +35,6 @@ export const Inputs = ({
setAdress, setAdress,
}: InputsProps) => { }: InputsProps) => {
const { settings } = useQuizData(); const { settings } = useQuizData();
console.log('phone',phone)
const FC = settings.cfg.formContact.fields; const FC = settings.cfg.formContact.fields;
if (!FC) return null; if (!FC) return null;

@ -9,6 +9,7 @@ import { useRootContainerSize } from "../../contexts/RootContainerWidthContext";
import type { QuizQuestionResult } from "../../model/questionTypes/result"; import type { QuizQuestionResult } from "../../model/questionTypes/result";
import { useQuizViewStore } from "@/stores/quizView"; import { useQuizViewStore } from "@/stores/quizView";
import { DESIGN_LIST } from "@/utils/designList"; import { DESIGN_LIST } from "@/utils/designList";
import { useEffect } from "react";
type ResultFormProps = { type ResultFormProps = {
resultQuestion: QuizQuestionResult; resultQuestion: QuizQuestionResult;
@ -23,7 +24,27 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
(state) => state.setCurrentQuizStep (state) => state.setCurrentQuizStep
); );
const spec = settings.cfg.spec; const spec = settings.cfg.spec;
console.log(quizThemes[settings.cfg.theme].isLight);
useEffect(() => {
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
`penaquiz-result-{${resultQuestion.id}}`
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: `penaquiz-result-{${resultQuestion.id}}`
});
};
}, [])
return ( return (
<Box <Box
@ -176,8 +197,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
<Box <Box
component={Link} component={Link}
target={"_blank"} target={"_blank"}
href={`https://${ href={`https://${window.location.hostname.includes("s") ? "s" : ""
window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`} }quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{ sx={{
display: "flex", display: "flex",

@ -30,9 +30,27 @@ export const StartPageViewPublication = () => {
const size = useRootContainerSize(); const size = useRootContainerSize();
const isMobile = size < 700; const isMobile = size < 700;
const isTablet = size >= 700 && size < 1100; const isTablet = size >= 700 && size < 1100;
console.log(settings)
const handleCopyNumber = () => { const handleCopyNumber = () => {
navigator.clipboard.writeText(settings.cfg.info.phonenumber); navigator.clipboard.writeText(settings.cfg.info.phonenumber);
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-phone"
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: "penaquiz-phone"
});
};
}; };
const background = const background =
@ -269,7 +287,29 @@ export const StartPageViewPublication = () => {
background: theme.palette.primary.main, background: theme.palette.primary.main,
borderRadius: "12px", borderRadius: "12px",
}} }}
onClick={() => setCurrentQuizStep("question")} onClick={() => {
setCurrentQuizStep("question")
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-startquiz"
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: "penaquiz-startquiz"
});
};
}}
> >
{settings.cfg.startpage.button.trim() {settings.cfg.startpage.button.trim()
? settings.cfg.startpage.button ? settings.cfg.startpage.button
@ -295,13 +335,40 @@ export const StartPageViewPublication = () => {
}} }}
> >
{settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center" && !isMobile && quizHeaderBlock} {settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center" && !isMobile && quizHeaderBlock}
<Box sx={{ maxWidth: "300px", <Box sx={{
maxWidth: "300px",
display: settings.cfg.startpageType === "centered" && isMobile || settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center" && isMobile ? "flex" : "block", display: settings.cfg.startpageType === "centered" && isMobile || settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center" && isMobile ? "flex" : "block",
flexDirection: "column", flexDirection: "column",
alignItems: "center", alignItems: "center",
order: settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center"? "2" : "0"}}> order: settings.cfg.startpageType === "expanded" && settings.cfg.startpage.position === "center" ? "2" : "0"
}}>
{settings.cfg.info.site && ( {settings.cfg.info.site && (
<Link href={settings.cfg.info.site} <ButtonBase
onClick={async () => {
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
await YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
"penaquiz-email"
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
await VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: "penaquiz-email"
});
};
location.href = (
settings.cfg.info.site.includes("https")
? settings.cfg.info.site
: `https://${settings.cfg.info.site}`
).replace(/\s+/g, '')
}}
> >
<Typography <Typography
sx={{ sx={{
@ -316,7 +383,8 @@ export const StartPageViewPublication = () => {
> >
{settings.cfg.info.site} {settings.cfg.info.site}
</Typography> </Typography>
</Link> </ButtonBase>
)} )}
{settings.cfg.info.clickable ? ( {settings.cfg.info.clickable ? (
isMobileDevice ? ( isMobileDevice ? (

@ -75,6 +75,7 @@ export default function ViewPublicationPage() {
</ThemeProvider> </ThemeProvider>
); );
let quizStepElement: ReactElement; let quizStepElement: ReactElement;
switch (currentQuizStep) { switch (currentQuizStep) {
case "startpage": { case "startpage": {

@ -47,8 +47,6 @@ export const UploadFile = ({
const uploadFile = async (file: File | undefined) => { const uploadFile = async (file: File | undefined) => {
if (isSending) return; if (isSending) return;
if (!file) return; if (!file) return;
console.log(file.size);
console.log(MAX_FILE_SIZE);
if (file.size > MAX_FILE_SIZE) return setModalWarningType("errorSize"); if (file.size > MAX_FILE_SIZE) return setModalWarningType("errorSize");
const isFileTypeAccepted = ACCEPT_SEND_FILE_TYPES_MAP[ const isFileTypeAccepted = ACCEPT_SEND_FILE_TYPES_MAP[
@ -68,7 +66,6 @@ export const UploadFile = ({
}, },
qid: quizId, qid: quizId,
}); });
console.log(data);
await sendAnswer({ await sendAnswer({
questionId: currentQuestion.id, questionId: currentQuestion.id,
@ -85,7 +82,7 @@ export const UploadFile = ({
0 0
); );
} catch (error) { } catch (error) {
console.log(error); console.error(error);
enqueueSnackbar("ответ не был засчитан"); enqueueSnackbar("ответ не был засчитан");
} }

@ -77,7 +77,7 @@ export const VariantItem = ({
currentQuestion.content.variants[index].points || 0 currentQuestion.content.variants[index].points || 0
); );
} catch (error) { } catch (error) {
console.log(error); console.error(error);
enqueueSnackbar("ответ не был засчитан"); enqueueSnackbar("ответ не был засчитан");
} }
@ -101,7 +101,7 @@ export const VariantItem = ({
: currentQuestion.content.variants[index].points || 0 : currentQuestion.content.variants[index].points || 0
); );
} catch (error) { } catch (error) {
console.log(error); console.error(error);
enqueueSnackbar("ответ не был засчитан"); enqueueSnackbar("ответ не был засчитан");
} }
@ -114,7 +114,7 @@ export const VariantItem = ({
preview, preview,
}); });
} catch (error) { } catch (error) {
console.log(error); console.error(error);
enqueueSnackbar("ответ не был засчитан"); enqueueSnackbar("ответ не был засчитан");
} }
deleteAnswer(currentQuestion.id); deleteAnswer(currentQuestion.id);

@ -17,6 +17,7 @@ export function useQuestionFlowControl() {
const setCurrentQuizStep = useQuizViewStore(state => state.setCurrentQuizStep); const setCurrentQuizStep = useQuizViewStore(state => state.setCurrentQuizStep);
const currentQuestion = sortedQuestions.find(question => question.id === currentQuestionId) ?? sortedQuestions[0]; const currentQuestion = sortedQuestions.find(question => question.id === currentQuestionId) ?? sortedQuestions[0];
console.log("currentQuestion", currentQuestion)
const linearQuestionIndex = currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled const linearQuestionIndex = currentQuestion && sortedQuestions.every(({ content }) => content.rule.parentId !== "root") // null when branching enabled
? sortedQuestions.indexOf(currentQuestion) ? sortedQuestions.indexOf(currentQuestion)
@ -149,6 +150,26 @@ export function useQuestionFlowControl() {
if (!nextQuestion) throw new Error("Next question not found"); if (!nextQuestion) throw new Error("Next question not found");
if (nextQuestion.type === "result") return showResult(); if (nextQuestion.type === "result") return showResult();
//засчитываем переход с вопроса дальше
//@ts-ignore
let YM = window?.ym;
//@ts-ignore
let VP = window?._tmr;
if (YM !== undefined && settings.cfg.yandexMetricNumber !== undefined) {
YM(
settings.cfg.yandexMetricNumber,
"reachGoal",
`penaquiz-step{${currentQuestion.id}}`
);
};
if (VP !== undefined && settings.cfg.vkMetricNumber !== undefined) {
VP.push({
type: "reachGoal",
id: settings.cfg.vkMetricNumber,
goal: `penaquiz-step{${currentQuestion.id}}`
});
};
setCurrentQuestionId(nextQuestion.id); setCurrentQuestionId(nextQuestion.id);
}, [nextQuestion, showResult]); }, [nextQuestion, showResult]);