Skip to content

Add Yandex Metrica support #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/analytics/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Do not write code directly here, instead use the `src` folder!
// Then, use this file to export everything you want your user to access.

export { default as GoogleAnalytics } from "./src/GoogleAnalytics.astro";
export { default as GoogleAnalytics } from "./src/GoogleAnalytics.astro";
export { default as YandexMetrica } from "./src/YandexMetrica.astro";
2 changes: 2 additions & 0 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"astrolib",
"google-analytics",
"ga4",
"yandex-analytics",
"yandex-metrica",
"astro-integration",
"withastro"
],
Expand Down
26 changes: 26 additions & 0 deletions packages/analytics/src/YandexMetrica.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
export interface Props {
id: string;
partytown?: boolean;
}

const { id = "YM_COUNTER_ID", partytown = false } = Astro.props;

const attrs = partytown ? { type: "text/partytown" } : {};
---

{/* <ShowIf id={id}> */}
<script is:inline {...attrs}>
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();
k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");

ym(id, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true
});
</script>
<noscript><div><img src={`https://mc.yandex.ru/watch/${id}`} style="position:absolute; left:-9999px;" alt="" /></div></noscript>
{/* </ShowIf> */}