From b163fd0f6cd9acb9bb0abe454eb982fe761114fc Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Thu, 17 Oct 2024 10:26:42 +0200 Subject: [PATCH] testing another tracker --- docs/src/components/Interpreter/index.tsx | 15 +++++++++++---- docs/src/theme/Footer/Layout/index.js | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/src/components/Interpreter/index.tsx b/docs/src/components/Interpreter/index.tsx index 715c38cd..57f6a627 100644 --- a/docs/src/components/Interpreter/index.tsx +++ b/docs/src/components/Interpreter/index.tsx @@ -15,6 +15,15 @@ export interface TerminalProps extends CSSProperties { '--size': string; } +function track(type: string, command: string) { + const umami = globalThis.umami as any; + const _paq = globalThis._paq as PiwikTrack; + if (umami) { + umami.track('REPL', [type, command]); + } + _paq.push(['trackEvent', 'REPL', type, command]); +} + type PiwikTrack = Array>; export type JQueryTerminal = ReturnType; @@ -31,9 +40,8 @@ const replReady = () => { function trackCommands(term: JQueryTerminal) { const ENTER = term.cmd().keymap('ENTER'); term.cmd().keymap('ENTER', function(e: KeyboardEvent, orig: () => any) { - const _paq = globalThis._paq as PiwikTrack; const command = term.get_command(); - _paq.push(['trackEvent', 'REPL', 'command', command]); + track('command', command); return ENTER(e, orig); }); } @@ -67,7 +75,6 @@ export default function Interpreter(): JSX.Element { }, []); function execSnippet(selector = '.example:visible') { - const _paq = globalThis._paq as PiwikTrack; const $ = globalThis.jQuery; const $snippet = $(selector); const code = $snippet.text(); @@ -75,7 +82,7 @@ export default function Interpreter(): JSX.Element { const term = $('.term').terminal(); term.echo(term.get_prompt(), { formatters: false }); term.exec(code, true); - _paq.push(['trackEvent', 'REPL', 'snippet', index + 1]); + track('snippet', index + 1); if (typeof screen.orientation === 'undefined') { setTimeout(() => term.focus(), 0); } diff --git a/docs/src/theme/Footer/Layout/index.js b/docs/src/theme/Footer/Layout/index.js index 8a8e7e46..2637be27 100644 --- a/docs/src/theme/Footer/Layout/index.js +++ b/docs/src/theme/Footer/Layout/index.js @@ -56,6 +56,7 @@ owa_cmds.push(['trackClicks']); _paq.push(['setSiteId', w]); g.type='text/javascript';g.async=true;g.defer=true;g.src=i;s.parentNode.insertBefore(g,s); })('https://jcubic.piwik.pro/ppms.php','https://jcubic.containers.piwik.pro/ppms.js','018719ec\u002D6793\u002D4a2d\u002D92f9\u002Db8b88a01d43c',document)`}}/> + ); }