Skip to content

Commit

Permalink
Merge pull request #5682 from kiva/verify-ty-badge-experiment-events-…
Browse files Browse the repository at this point in the history
…MP-1011

feat: add tracking events to typage components
  • Loading branch information
christian14b authored Nov 14, 2024
2 parents 09e9877 + c7f0477 commit 124429d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 23 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,
},
numberOfBadges: {
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.numberOfBadges,
);
if (value) {
try {
apollo.mutate({
Expand Down
78 changes: 66 additions & 12 deletions src/components/Thanks/MyKiva/ThanksBadges.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<!-- Opt In module -->
<OptInModule
v-if="!isGuest && !isOptedIn"
:selected-loan="selectedLoan"
:loans="loans"
:is-guest="isGuest"
:number-of-badges="numberOfBadges"
/>
<!-- Badges module -->
<div class="content-box tw-flex tw-flex-col tw-items-center tw-gap-1.5 tw-text-center">
Expand Down Expand Up @@ -36,7 +36,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',
numberOfBadges,
]"
>
{{ continueButtonText }}
<KvMaterialIcon :icon="mdiArrowRight" class="tw-ml-0.5" />
</KvButton>
Expand All @@ -50,7 +59,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 +79,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="numberOfBadges"
/>
</div>
</KvExpandable>
Expand All @@ -80,7 +91,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 +144,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="numberOfBadges"
/>
</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,10 +200,6 @@ const props = defineProps({
type: Object,
default: () => ({}),
},
selectedLoan: {
type: Object,
default: () => ({})
}
});
const { getHighestPriorityDisplayBadge, getLastCompletedBadgeLevelData } = useBadgeData();
Expand All @@ -196,6 +209,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 +248,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',
numberOfBadges.value,
);
} 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',
numberOfBadges.value,
);
// 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',
numberOfBadges.value,
);
openCreateAccount.value = !openCreateAccount.value;
};
const handleClickOrderConfirmation = () => {
$kvTrackEvent(
'post-checkout',
'click',
'open-order-confirmation-drawer',
props.isGuest ? 'guest' : 'signed-in',
numberOfBadges.value,
);
openOrderConfirmation.value = !openOrderConfirmation.value;
};
onMounted(() => {
confetti({
origin: {
Expand Down

0 comments on commit 124429d

Please sign in to comment.