|
3 | 3 | import { generateShareUrl, getShareText, shareLinks, copyToClipboard } from '$lib/utils/sharing'; |
4 | 4 | import { quizStore } from '$lib/stores/quiz'; |
5 | 5 | import { mbtiDescriptions, type MBTIType } from '$lib/data/mbti-descriptions'; |
| 6 | + import { onMount } from 'svelte'; |
| 7 | + import { browser } from '$app/environment'; |
| 8 | + import posthog from 'posthog-js'; |
6 | 9 |
|
7 | 10 | export let language: Language; |
8 | 11 | export let onRestart: () => void; |
9 | 12 |
|
10 | 13 | let copied = false; |
11 | 14 |
|
| 15 | + // Track when results page is reached |
| 16 | + onMount(() => { |
| 17 | + if (browser) { |
| 18 | + posthog.capture('quiz_completed', { |
| 19 | + language: language.name, |
| 20 | + language_id: language.id, |
| 21 | + mbti_type: $quizStore.mbtiType, |
| 22 | + mbti_questions_answered: $quizStore.mbtiAnswers.length, |
| 23 | + language_questions_answered: $quizStore.languageAnswers.length |
| 24 | + }); |
| 25 | + } |
| 26 | + }); |
| 27 | +
|
12 | 28 | $: shareUrl = generateShareUrl({ |
13 | 29 | languageId: language.id, |
14 | 30 | mbtiType: $quizStore.mbtiType |
|
20 | 36 | if (success) { |
21 | 37 | copied = true; |
22 | 38 | setTimeout(() => (copied = false), 2000); |
| 39 | + if (browser) { |
| 40 | + posthog.capture('share_clicked', { |
| 41 | + platform: 'copy_link', |
| 42 | + language: language.name, |
| 43 | + mbti_type: $quizStore.mbtiType |
| 44 | + }); |
| 45 | + } |
23 | 46 | } |
24 | 47 | } |
25 | 48 |
|
26 | 49 | function handleShare(platform: keyof typeof shareLinks) { |
27 | 50 | const url = shareLinks[platform](shareUrl, shareText); |
28 | 51 | window.open(url, '_blank', 'width=600,height=400'); |
| 52 | + if (browser) { |
| 53 | + posthog.capture('share_clicked', { |
| 54 | + platform, |
| 55 | + language: language.name, |
| 56 | + mbti_type: $quizStore.mbtiType |
| 57 | + }); |
| 58 | + } |
29 | 59 | } |
30 | 60 | </script> |
31 | 61 |
|
|
0 commit comments