Skip to content

Commit

Permalink
testing another tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Oct 17, 2024
1 parent 827f99c commit b163fd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions docs/src/components/Interpreter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Array<string>>;
export type JQueryTerminal = ReturnType<typeof globalThis.terminal>;

Expand All @@ -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);
});
}
Expand Down Expand Up @@ -67,15 +75,14 @@ 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();
const index = $snippet.closest('li').index();
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);
}
Expand Down
1 change: 1 addition & 0 deletions docs/src/theme/Footer/Layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`}}/>
<script defer src="https://cloud.umami.is/script.js" data-website-id="422bfe77-bcfe-4cf8-a923-d496fba1bcc3"></script>
</footer>
);
}

0 comments on commit b163fd0

Please sign in to comment.