Skip to content

Commit

Permalink
Add event registration
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-mn-yral committed Feb 27, 2024
1 parent 9e48325 commit 0ac57a3
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 13 deletions.
21 changes: 20 additions & 1 deletion packages/web-client/src/lib/components/popup/UserStudy.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script lang="ts">
import { submitUserStudyInfo } from '$lib/helpers/user-study'
import { submitUserStudyInfo, userStoryStore } from '$lib/helpers/user-study'
import { userProfile } from '$lib/stores/app'
import { authState } from '$lib/stores/auth'
import { registerEvent } from '@hnn/components/analytics/GA.utils'
import Button from '@hnn/components/button/Button.svelte'
import Input from '@hnn/components/input/Input.svelte'
import OverlayPopup from '@hnn/components/popup/OverlayPopup.svelte'
Expand All @@ -21,6 +24,14 @@ async function sendInfoToBackend() {
return
}
await submitUserStudyInfo(email, name)
registerEvent('beta_tester_submit', {
user_id: $authState.idString,
display_name: $userProfile.display_name,
feed_type: $userStoryStore.feedType,
video_id: $userStoryStore.videoId,
video_publisher_id: $userStoryStore.videoCanisterId,
video_ref_id: `${$userStoryStore.videoCanisterId}@${$userStoryStore.videoId}`,
})
finished = true
} finally {
loading = false
Expand All @@ -29,6 +40,14 @@ async function sendInfoToBackend() {
async function doNotShowAgain() {
if (!finished) {
registerEvent('beta_tester_reject', {
user_id: $authState.idString,
display_name: $userProfile.display_name,
feed_type: $userStoryStore.feedType,
video_id: $userStoryStore.videoId,
video_publisher_id: $userStoryStore.videoCanisterId,
video_ref_id: `${$userStoryStore.videoCanisterId}@${$userStoryStore.videoId}`,
})
await submitUserStudyInfo('not-interested', 'not-interested')
}
show = false
Expand Down
15 changes: 12 additions & 3 deletions packages/web-client/src/lib/helpers/user-study.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ const userIds = [
let timer: ReturnType<typeof setInterval>
let secsPassed = 0

export const showUserStudyPopup = writable(false)
export const userStoryStore = writable({
show: false,
videoId: '',
videoCanisterId: '',
feedType: '',
})

export function submitUserStudyInfo(email: string, name: string) {
const state = get(authState)
Expand All @@ -58,15 +63,19 @@ async function toShowUserStudyPopup() {
}
}

export function monitorForUserStudy(userId: string, countTill: number) {
export function monitorForUserStudy(
userId: string,
countTill: number,
cb: Function,
) {
secsPassed = 0
clearMonitoring()
if (!userIds.includes(userId)) return
timer = setInterval(async () => {
if (secsPassed > countTill) {
clearMonitoring()
if (await toShowUserStudyPopup()) {
showUserStudyPopup.set(true)
cb()
}
} else {
secsPassed++
Expand Down
6 changes: 3 additions & 3 deletions packages/web-client/src/routes/(feed)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { onDestroy, onMount } from 'svelte'
import { authState } from '$lib/stores/auth'
import IconButton from '@hnn/components/button/IconButton.svelte'
import { browser } from '$app/environment'
import { showUserStudyPopup } from '$lib/helpers/user-study'
import { userStoryStore } from '$lib/helpers/user-study'
import UserStudy from '$lib/components/popup/UserStudy.svelte'
function handleVisibilityChange() {
Expand Down Expand Up @@ -73,6 +73,6 @@ $: pathname = $page.url.pathname
</div>
</HomeLayout>

{#if $showUserStudyPopup}
<UserStudy bind:show={$showUserStudyPopup} />
{#if $userStoryStore.show}
<UserStudy bind:show={$userStoryStore.show} />
{/if}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ import Log from '$lib/utils/Log'
import { updateURL } from '$lib/utils/feedUrl'
import { handleParams } from '$lib/utils/params'
import { joinArrayUniquely } from '$lib/utils/video'
import { appPrefs, homeFeedVideos, playerState } from '$lib/stores/app'
import {
appPrefs,
homeFeedVideos,
playerState,
userProfile,
} from '$lib/stores/app'
import { removeSplashScreen } from '$lib/stores/popups'
import { onDestroy, onMount, tick } from 'svelte'
import { debounce } from 'throttle-debounce'
import type { PageData } from './$types'
import { browser } from '$app/environment'
import { clearMonitoring, monitorForUserStudy } from '$lib/helpers/user-study'
import {
clearMonitoring,
monitorForUserStudy,
userStoryStore,
} from '$lib/helpers/user-study'
import { authState } from '$lib/stores/auth'
import { registerEvent } from '@hnn/components/analytics/GA.utils'
export let data: PageData
Expand Down Expand Up @@ -127,7 +137,23 @@ const handleChange = debounce(250, (newIndex: number) => {
// User study
if (!userStudyInit && currentVideoIndex > 2) {
userStudyInit = true
monitorForUserStudy($authState.idString || '', 300)
monitorForUserStudy($authState.idString || '', 300, () => {
$userStoryStore = {
show: true,
feedType: 'main_feed',
videoCanisterId:
videos[currentVideoIndex].publisher_canister_id.toString(),
videoId: videos[currentVideoIndex].id.toString(),
}
registerEvent('popup_viewed', {
user_id: $authState.idString,
display_name: $userProfile.display_name,
feed_type: $userStoryStore.feedType,
video_id: $userStoryStore.videoId,
video_publisher_id: $userStoryStore.videoCanisterId,
video_ref_id: `${$userStoryStore.videoCanisterId}@${$userStoryStore.videoId}`,
})
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ import { updateURL } from '$lib/utils/feedUrl'
import Log from '$lib/utils/Log'
import { handleParams } from '$lib/utils/params'
import { joinArrayUniquely } from '$lib/utils/video'
import { appPrefs, hotOrNotFeedVideos, playerState } from '$lib/stores/app'
import {
appPrefs,
hotOrNotFeedVideos,
playerState,
userProfile,
} from '$lib/stores/app'
import { removeSplashScreen } from '$lib/stores/popups'
import { onMount, tick } from 'svelte'
import type { PageData } from './$types'
import { debounce } from 'throttle-debounce'
import { browser } from '$app/environment'
import { monitorForUserStudy } from '$lib/helpers/user-study'
import { monitorForUserStudy, userStoryStore } from '$lib/helpers/user-study'
import { authState } from '$lib/stores/auth'
import { registerEvent } from '@hnn/components/analytics/GA.utils'
export let data: PageData
Expand Down Expand Up @@ -120,7 +126,23 @@ const handleChange = debounce(250, (newIndex: number) => {
// User study
if (!userStudyInit && currentVideoIndex > 2) {
userStudyInit = true
monitorForUserStudy($authState.idString || '', 300)
monitorForUserStudy($authState.idString || '', 300, () => {
$userStoryStore = {
show: true,
feedType: 'hot_or_not_feed',
videoCanisterId:
videos[currentVideoIndex].publisher_canister_id.toString(),
videoId: videos[currentVideoIndex].id.toString(),
}
registerEvent('popup_viewed', {
user_id: $authState.idString,
display_name: $userProfile.display_name,
feed_type: $userStoryStore.feedType,
video_id: $userStoryStore.videoId,
video_publisher_id: $userStoryStore.videoCanisterId,
video_ref_id: `${$userStoryStore.videoCanisterId}@${$userStoryStore.videoId}`,
})
})
}
})
Expand Down

0 comments on commit 0ac57a3

Please sign in to comment.