Skip to content

Commit

Permalink
feat: add tracking events to typage components
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Bedon committed Nov 14, 2024
1 parent 09e9877 commit 261fb3d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
16 changes: 15 additions & 1 deletion src/components/Forms/GuestAccountCreation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ export default {
type: String,
default: 'create-guest-account'
},
eventProperty: {
type: String,
default: ''
},
eventValue: {
type: Number,
default: 0
}
},
data() {
return {
Expand All @@ -93,7 +101,13 @@ export default {
this.serverError = false;
this.v$.$touch();
if (!this.v$.$invalid) {
this.$kvTrackEvent(this.eventCategory, 'click', this.eventLabel);
this.$kvTrackEvent(
this.eventCategory,
'click',
this.eventLabel,
this.eventProperty,
this.eventValue ? this.eventValue : null
);
// will end up redirecting to password reset page.
this.apollo.mutate({
Expand Down
27 changes: 17 additions & 10 deletions src/components/Thanks/MyKiva/OptInModule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,13 @@
<kv-button
class="tw-w-full btn"
@click="() => updateOptIn(true)"
v-kv-track-event="[
'thanks',
'click',
'accept-opt-in-request',
]"
>
Yes, keep me updated
</kv-button>
<kv-button
@click="() => updateOptIn(false)"
variant="ghost"
class="tw-w-full btn ghost"
v-kv-track-event="[
'thanks',
'click',
'reject-opt-in-request',
]"
>
No, I don’t want to receive updates
</kv-button>
Expand Down Expand Up @@ -82,10 +72,19 @@ const props = defineProps({
optedIn: {
type: Boolean,
default: false
},
isGuest: {
type: Boolean,
default: false,
},
numberOfBadgesEarned: {
type: Number,
default: 0,
}
});
const apollo = inject('apollo');
const $kvTrackEvent = inject('$kvTrackEvent');
const newConsentAnswered = ref(false);
const receiveNews = ref(false);
Expand Down Expand Up @@ -140,6 +139,14 @@ const getMarginLeft = index => {
};
const updateOptIn = value => {
$kvTrackEvent(
'post-checkout',
'click',
`${value ? 'accept' : 'reject'}-opt-in-request`,
props.isGuest ? 'guest' : 'signed-in',
props.numberOfBadgesEarned,
);
if (value) {
try {
apollo.mutate({
Expand Down
79 changes: 68 additions & 11 deletions src/components/Thanks/MyKiva/ThanksBadges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<!-- Opt In module -->
<OptInModule
v-if="!isGuest && !isOptedIn"
:selected-loan="selectedLoan"
:loans="loans"
:is-guest="isGuest"
/>
Expand Down Expand Up @@ -36,7 +35,16 @@
</BadgeContainer>
<h3>{{ badgeLevelName }} unlocked</h3>
<p>{{ badgeFunFact }}{{ badgeFunFactFootnote ? '*' : '' }}</p>
<KvButton class="continue-button tw-w-full tw-my-0.5" @click="handleContinue">
<KvButton
class="continue-button tw-w-full tw-my-0.5" @click="handleContinue"
v-kv-track-event="[
'post-checkout',
'click',
'create-new-account',
isGuest ? 'guest' : 'signed-in',
numberOfBadgesEarned,
]"
>
{{ continueButtonText }}
<KvMaterialIcon :icon="mdiArrowRight" class="tw-ml-0.5" />
</KvButton>
Expand All @@ -50,7 +58,7 @@
<div
class="option-box"
:class="{ 'open' : openCreateAccount }"
@click="openCreateAccount = !openCreateAccount"
@click="handleClickCreateAccount"
>
<p class="tw-font-medium">
Create your account
Expand All @@ -70,8 +78,10 @@
<p>Finish setting up your account to track and relend your money as you are paid back.</p>
<GuestAccountCreation
class="tw-pt-3"
event-category="thanks"
event-label="open-account-creation-drawer"
event-category="post-checkout"
event-label="create-new-account-from-drawer"
event-property="guest"
:event-value="numberOfBadgesEarned"
/>
</div>
</KvExpandable>
Expand All @@ -80,7 +90,7 @@
<div
class="option-box"
:class="{ 'open' : openOrderConfirmation }"
@click="openOrderConfirmation = !openOrderConfirmation"
@click="handleClickOrderConfirmation"
>
<p class="tw-font-medium">
Show confirmation
Expand Down Expand Up @@ -133,13 +143,19 @@
title="Finish creating your account to see what's next"
@lightbox-closed="showGuestAccountModal = false"
>
<GuestAccountCreation />
<GuestAccountCreation
event-label="create-new-account"
event-property="guest"
:event-value="numberOfBadgesEarned"
/>
</KvLightbox>
</div>
</template>

<script setup>
import { onMounted, ref, computed } from 'vue';
import {
onMounted, ref, computed, inject
} from 'vue';
import confetti from 'canvas-confetti';
import KvMaterialIcon from '@kiva/kv-components/vue/KvMaterialIcon';
import KvExpandable from '#src/components/Kv/KvExpandable';
Expand Down Expand Up @@ -183,9 +199,9 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
selectedLoan: {
type: Object,
default: () => ({})
numberOfBadgesEarned: {
type: Number,
default: 0
}
});
Expand All @@ -196,6 +212,8 @@ const openOrderConfirmation = ref(false);
const openShareModule = ref(false);
const showGuestAccountModal = ref(false);
const $kvTrackEvent = inject('$kvTrackEvent');
const numberOfBadges = computed(() => props.badgesAchieved.length);
const loansToDisplay = computed(() => props.loans.slice(0, 3));
Expand Down Expand Up @@ -233,14 +251,53 @@ const badgeFunFactFootnote = computed(() => badgeData.value.contentfulData?.shar
const handleContinue = () => {
if (props.isGuest) {
showGuestAccountModal.value = true;
$kvTrackEvent(
'post-checkout',
'click',
'open-account-creation-drawer',
'guest',
props.numberOfBadgesEarned,
);
} else {
const hasBadges = numberOfBadges.value > 0;
const sectionToScrollTo = numberOfBadges.value === 1 ? MY_IMPACT_JOURNEYS_ID : MY_ACHIEVEMENTS_ID;
$kvTrackEvent(
'post-checkout',
'click',
'continue-to-my-kiva',
'guest',
props.numberOfBadgesEarned,
);
// eslint-disable-next-line vue/no-mutating-props
props.router?.push(`/portfolio${hasBadges ? `#${sectionToScrollTo}` : ''}`);
}
};
const handleClickCreateAccount = () => {
$kvTrackEvent(
'post-checkout',
'click',
'open-account-creation-drawer',
'guest',
props.numberOfBadgesEarned,
);
openCreateAccount.value = !openCreateAccount.value;
};
const handleClickOrderConfirmation = () => {
$kvTrackEvent(
'post-checkout',
'click',
'open-order-confirmation-drawer',
props.isGuest ? 'guest' : 'signed-in',
props.numberOfBadgesEarned,
);
openOrderConfirmation.value = !openOrderConfirmation.value;
};
onMounted(() => {
confetti({
origin: {
Expand Down

0 comments on commit 261fb3d

Please sign in to comment.