diff --git a/src/analytics.js b/src/analytics.js
new file mode 100644
index 0000000..50dc283
--- /dev/null
+++ b/src/analytics.js
@@ -0,0 +1,32 @@
+import { el } from "./utils.js";
+
+class Analytics {
+ static event(name, data = undefined) {
+ if (typeof ym !== 'undefined') {
+ // eslint-disable-next-line no-undef
+ ym(window.YANDEX_METRICA_ID, 'reachGoal', name, data);
+ }
+ }
+}
+
+document.addEventListener("DOMContentLoaded", function () {
+ const popupPVZId = el("popup-pvz-id");
+ const pvzData = { pvz: popupPVZId.innerText };
+
+ const popupLink = el("popup-link");
+ const sourceLink = el("popup-source");
+ const infoPopupButton = el("info-popup-button");
+
+ popupLink.addEventListener("click", function () {
+ Analytics.event("pvz-link-clicked", pvzData);
+ });
+
+ sourceLink.addEventListener("click", function () {
+ Analytics.event("pvz-link-clicked", pvzData);
+ });
+
+ infoPopupButton.addEventListener("click", function () {
+ Analytics.event("info-popup-closed");
+ });
+});
+
diff --git a/src/index.html b/src/index.html
index 3c6dc83..5df0f0c 100644
--- a/src/index.html
+++ b/src/index.html
@@ -93,7 +93,7 @@
Больше не показывать
-
+
diff --git a/src/main.js b/src/main.js
index 508de4a..6a25952 100644
--- a/src/main.js
+++ b/src/main.js
@@ -4,6 +4,7 @@ import map from "./map";
import "./info-popup";
import "./popup";
+import "./analytics";
import mergedData from "../merged-data.json";
import { createFeatures } from "./features";
diff --git a/vite.config.js b/vite.config.js
index d2d5ddd..b85bb77 100644
--- a/vite.config.js
+++ b/vite.config.js
@@ -1,26 +1,35 @@
import webfontDownload from "vite-plugin-webfont-dl";
import { VitePluginRadar } from "vite-plugin-radar";
-import htmlPlugin from 'vite-plugin-html-config'
+import htmlPlugin from "vite-plugin-html-config";
-const metas = []
+const metas = [];
+const headScripts = [];
+
+console.log(process.env.YANDEX_METRICA_ID)
if (process.env.YANDEX_VERIFICATION) {
metas.push({
- name: 'yandex-verification',
- content: process.env.YANDEX_VERIFICATION
- })
+ name: "yandex-verification",
+ content: process.env.YANDEX_VERIFICATION,
+ });
}
-const PUBLIC_URL = process.env.PUBLIC_URL || process.env.VERCEL_PROJECT_PRODUCTION_URL
+if (process.env.YANDEX_METRICA_ID) {
+ headScripts.push(
+ `window.YANDEX_METRICA_ID=${process.env.YANDEX_METRICA_ID}`,
+ );
+}
+
+const PUBLIC_URL =
+ process.env.PUBLIC_URL || process.env.VERCEL_PROJECT_PRODUCTION_URL;
if (PUBLIC_URL) {
metas.push({
- name: 'og:url',
- content: 'https://' + PUBLIC_URL
- })
+ name: "og:url",
+ content: "https://" + PUBLIC_URL,
+ });
}
-
export default {
root: "src",
build: {
@@ -35,6 +44,7 @@ export default {
}),
htmlPlugin({
metas,
- },)
+ headScripts,
+ }),
],
};