@deep-foundation/deepcase
Version:
[](https://gitpod.io/#https://github.com/deep-foundation/deepcase) [](https://discord.gg/deep-
45 lines • 1.74 kB
JavaScript
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