Skip to content

Commit

Permalink
fix: send sign in event
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed May 14, 2024
1 parent f03ff4d commit 464ef76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/components/EmailForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { Field as FormField, useForm } from 'vee-validate'
import { useAutoAnimate } from '@formkit/auto-animate/vue'
import * as z from 'zod'
import { useModel } from 'vue'
import { sendTrack } from '~/lib/tracking'
const props = defineProps<{
email: string
}>()
defineEmits<{
const emit = defineEmits<{
signedIn: []
'update:email': [string]
}>()
Expand Down Expand Up @@ -38,6 +40,7 @@ const onSubmit = form.handleSubmit(async (values) => {
if (res.ok && res.token) {
$paywall.setKey('token', res.token)
}
emit('signedIn')
// TODO: error handling
})
Expand Down
11 changes: 10 additions & 1 deletion src/components/LeakyPaywall.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ onMounted(() => {
show: (v = true) => (show.value = v),
})
})
function handleSignedIn() {
sendTrack('subscriber.signed_in', {
pathname: location.value.pathname ?? '',
// impossible to be empty
article_id: foundArticle.value?.id ?? '',
client_id: config.value.clientId,
})
}
</script>

<template>
Expand All @@ -199,7 +208,7 @@ onMounted(() => {
<!-- for accessibility -->
<AlertDialogTitle class="invisible">Subscribe</AlertDialogTitle>
</VisuallyHidden>
<LeakyPaywallContent v-model:email="emailInput" :config="config" />
<LeakyPaywallContent v-model:email="emailInput" :config="config" @signed-in="handleSignedIn" />
</AlertDialogContent>
</AlertDialog>
<VisuallyHidden>
Expand Down
4 changes: 3 additions & 1 deletion src/components/LeakyPaywallContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface Props {
const props = defineProps<Props>()
defineEmits<{ signedIn: [] }>()
const themeConfig = computed(() => ({ '--sp-primary': props.config.primaryColor }))
const email = defineModel('email', {
default: '',
Expand Down Expand Up @@ -34,7 +36,7 @@ const email = defineModel('email', {
</p>

<!-- email form -->
<EmailForm v-model:email="email" />
<EmailForm v-model:email="email" @signed-in="$emit('signedIn')" />
</div>
</CardContent>
</Card>
Expand Down

0 comments on commit 464ef76

Please sign in to comment.