UNPKG

@deep-foundation/deepcase

Version:

[![Gitpod](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/deep-foundation/deepcase) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label&color=purple)](https://discord.gg/deep-

45 lines 1.74 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import React, { useEffect, useContext } from 'react'; import { useRouter } from 'next/router'; import ym, { YMInitializer } from 'react-yandex-metrika'; import ga from 'react-ga'; export const AnalyticsContext = React.createContext({ event(eventName) { ym('reachGoal', eventName); ga.event({ category: 'events', action: eventName, }); } }); export function useAnalitics(context = AnalyticsContext) { return useContext(context); } ; const RouterAnalytics = () => { const router = useRouter(); useEffect(() => { ga.pageview(router === null || router === void 0 ? void 0 : router.asPath); }, []); return null; }; export const Analitics = React.memo(({ yandexMetrikaAccounts = [], googleAnalyticsAccounts = [], context = AnalyticsContext, debug = false, children, }) => { useEffect(() => { const account = googleAnalyticsAccounts === null || googleAnalyticsAccounts === void 0 ? void 0 : googleAnalyticsAccounts[0]; if (account) ga.initialize({ trackingId: account, }, { debug, }); }, []); return _jsxs(_Fragment, { children: [_jsx(YMInitializer, { accounts: yandexMetrikaAccounts, options: { clickmap: true, webvisor: true, ecommerce: true, trackHash: true, trackLinks: true, triggerEvent: true, } }), _jsxs(context.Provider, { value: {}, children: [_jsx(RouterAnalytics, {}), children] })] }); }); //# sourceMappingURL=analitics.js.map