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

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,
});
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(() => {
if (rootContainerRef.current) setRootContainerWidth(rootContainerRef.current.clientWidth);
}, []);

@ -141,7 +141,25 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
sessions[quizId] = Date.now();
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) {
enqueueSnackbar("повторите попытку позже");
}
@ -152,6 +170,26 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
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 (
<Box
@ -175,8 +213,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
settings.cfg.design && !isMobile
? quizThemes[settings.cfg.theme].isLight
? `url(${DESIGN_LIST[settings.cfg.theme]})`
: `linear-gradient(90deg, #272626, transparent), url(${
DESIGN_LIST[settings.cfg.theme]
: `linear-gradient(90deg, #272626, transparent), url(${DESIGN_LIST[settings.cfg.theme]
})`
: null,
}}
@ -334,8 +371,7 @@ export const ContactForm = ({ currentQuestion, onShowResult }: Props) => {
<Box
component={Link}
target={"_blank"}
href={`https://${
window.location.hostname.includes("s") ? "s" : ""
href={`https://${window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{
display: "flex",

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

@ -9,6 +9,7 @@ import { useRootContainerSize } from "../../contexts/RootContainerWidthContext";
import type { QuizQuestionResult } from "../../model/questionTypes/result";
import { useQuizViewStore } from "@/stores/quizView";
import { DESIGN_LIST } from "@/utils/designList";
import { useEffect } from "react";
type ResultFormProps = {
resultQuestion: QuizQuestionResult;
@ -23,7 +24,27 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
(state) => state.setCurrentQuizStep
);
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 (
<Box
@ -176,8 +197,7 @@ export const ResultForm = ({ resultQuestion }: ResultFormProps) => {
<Box
component={Link}
target={"_blank"}
href={`https://${
window.location.hostname.includes("s") ? "s" : ""
href={`https://${window.location.hostname.includes("s") ? "s" : ""
}quiz.pena.digital/squiz/quiz/logo?q=${quizId}`}
sx={{
display: "flex",

@ -30,9 +30,27 @@ export const StartPageViewPublication = () => {
const size = useRootContainerSize();
const isMobile = size < 700;
const isTablet = size >= 700 && size < 1100;
console.log(settings)
const handleCopyNumber = () => {
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 =
@ -269,7 +287,29 @@ export const StartPageViewPublication = () => {
background: theme.palette.primary.main,
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
@ -295,13 +335,40 @@ export const StartPageViewPublication = () => {
}}
>
{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",
flexDirection: "column",
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 && (
<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
sx={{
@ -316,7 +383,8 @@ export const StartPageViewPublication = () => {
>
{settings.cfg.info.site}
</Typography>
</Link>
</ButtonBase>
)}
{settings.cfg.info.clickable ? (
isMobileDevice ? (

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

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

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

@ -17,6 +17,7 @@ export function useQuestionFlowControl() {
const setCurrentQuizStep = useQuizViewStore(state => state.setCurrentQuizStep);
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
? sortedQuestions.indexOf(currentQuestion)
@ -149,6 +150,26 @@ export function useQuestionFlowControl() {
if (!nextQuestion) throw new Error("Next question not found");
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);
}, [nextQuestion, showResult]);