Skip to content

Commit

Permalink
πŸ“ˆ Store utm info to session storage (#1782)
Browse files Browse the repository at this point in the history
* πŸ“ˆ Store utm info to session storage

* 🎨 Simplify internal referrer list in utm
  • Loading branch information
williamchong authored Sep 10, 2024
1 parent 157244a commit 5f5c130
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/components/NFTBook/CrossSellDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: `${this.utmSource}_cross-sell`,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
email: this.walletEmail,
});
if (url) {
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
email: this.walletEmail,
});
if (url) {
Expand All @@ -1281,7 +1281,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
};
if (this.walletEmail) {
body.email = this.walletEmail;
Expand Down
59 changes: 49 additions & 10 deletions src/mixins/utm.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { setSessionStorageItem, getFromSessionStorage } from '@/util/misc';

const INTERNAL_REFERRERS = [
'https://liker.land',
'https://authcore.like.co',
'https://checkout.stripe.com',
];

export default {
computed: {
utmCampaign() {
return this.$route.query.utm_campaign;
},
utmSource() {
return this.$route.query.utm_source;
},
utmMedium() {
return this.$route.query.utm_medium;
},
data() {
return {
utmCampaign: this.$route.query.utm_campaign,
utmSource: this.$route.query.utm_source,
utmMedium: this.$route.query.utm_medium,
documentReferrer: '',
};
},
mounted() {
this.documentReferrer = document.referrer;
this.restoreUTMFromSessionStorage();
this.storeUTMToSessionStorage();
},
methods: {
getUtmProps({
Expand All @@ -22,5 +32,34 @@ export default {
utmMedium: this.utmMedium || defaultUtmMedium,
};
},
restoreUTMFromSessionStorage() {
const utm = JSON.parse(getFromSessionStorage('UTM_INFO'));
if (utm) {
if (!this.utmCampaign) this.utmCampaign = utm.utmCampaign;
if (!this.utmSource) this.utmSource = utm.utmSource;
if (!this.utmMedium) this.utmMedium = utm.utmMedium;
if (
!this.documentReferrer ||
(utm.documentReferrer &&
INTERNAL_REFERRERS.find(referrer =>
this.documentReferrer.includes(referrer)
) &&
INTERNAL_REFERRERS.find(referrer =>
utm.documentReferrer.includes(referrer)
))
) {
this.documentReferrer = utm.documentReferrer;
}
}
},
storeUTMToSessionStorage() {
const utm = {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
documentReferrer: this.documentReferrer,
};
setSessionStorageItem('UTM_INFO', JSON.stringify(utm));
},
},
};
6 changes: 2 additions & 4 deletions src/mixins/wallet-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mapActions } from 'vuex';

import alertMixin from '~/mixins/alert';
import { logTrackerEvent } from '~/util/EventLogger';
import { setSessionStorageItem } from '~/util/misc';

export default {
mixins: [alertMixin],
Expand Down Expand Up @@ -29,10 +30,7 @@ export default {
'connect_wallet_start',
1
);
window.sessionStorage.setItem(
'USER_POST_AUTH_ROUTE',
this.$route.fullPath
);
setSessionStorageItem('USER_POST_AUTH_ROUTE', this.$route.fullPath);
const connection = isOpenAuthcore
? await this.openAuthcoreModal({ isSignUp })
: await this.openConnectWalletModal({
Expand Down
2 changes: 1 addition & 1 deletion src/pages/nft/class/_classId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
email: this.walletEmail,
});
if (url) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/nft/collection/_collectionId/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
email: this.walletEmail,
});
if (url) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/shopping-cart/book.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default {
utmCampaign: this.utmCampaign,
utmSource: this.utmSource,
utmMedium: this.utmMedium,
referrer: document.referrer,
referrer: this.documentReferrer,
items: this.shoppingCartBookItems,
email: this.walletEmail,
});
Expand Down
14 changes: 14 additions & 0 deletions src/util/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ export function getContentUrlType(url) {
return undefined;
}

export function getFromSessionStorage(key) {
if (window.sessionStorage) {
return window.sessionStorage.getItem(key);
}
return null;
}

export function setSessionStorageItem(key, item) {
if (window.sessionStorage) {
return window.sessionStorage.setItem(key, item);
}
return undefined;
}

export default sleep;

0 comments on commit 5f5c130

Please sign in to comment.