chore: Reduce the click area on Branding (#1340)

This commit is contained in:
Pranav Raj S 2020-10-15 00:11:47 +05:30 committed by GitHub
parent 0bea0217b4
commit 666948b809
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 31 deletions

View file

@ -185,7 +185,8 @@ export const IFrameHelper = {
}, },
setCurrentUrl: () => { setCurrentUrl: () => {
IFrameHelper.sendMessage('set-current-url', { IFrameHelper.sendMessage('set-current-url', {
refererURL: window.location.href, referrerURL: window.location.href,
referrerHost: window.location.host,
}); });
}, },
toggleCloseButton: () => { toggleCloseButton: () => {

View file

@ -1,3 +1,4 @@
export const BUS_EVENTS = { export const BUS_EVENTS = {
SET_REFERRER_HOST: 'SET_REFERRER_HOST',
SET_TWEET_REPLY: 'SET_TWEET_REPLY', SET_TWEET_REPLY: 'SET_TWEET_REPLY',
}; };

View file

@ -23,6 +23,7 @@ import { IFrameHelper } from 'widget/helpers/utils';
import Router from './views/Router'; import Router from './views/Router';
import { getLocale } from './helpers/urlParamsHelper'; import { getLocale } from './helpers/urlParamsHelper';
import { BUS_EVENTS } from 'shared/constants/busEvents';
export default { export default {
name: 'App', name: 'App',
@ -156,7 +157,8 @@ export default {
} else if (message.event === 'widget-visible') { } else if (message.event === 'widget-visible') {
this.scrollConversationToBottom(); this.scrollConversationToBottom();
} else if (message.event === 'set-current-url') { } else if (message.event === 'set-current-url') {
window.refererURL = message.refererURL; window.referrerURL = message.referrerURL;
bus.$emit(BUS_EVENTS.SET_REFERRER_HOST, message.referrerHost);
} else if (message.event === 'toggle-close-button') { } else if (message.event === 'toggle-close-button') {
this.isMobile = message.showClose; this.isMobile = message.showClose;
} else if (message.event === 'push-event') { } else if (message.event === 'push-event') {

View file

@ -1,7 +1,7 @@
import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper'; import { buildSearchParamsWithLocale } from '../helpers/urlParamsHelper';
const sendMessage = content => { const sendMessage = content => {
const refererURL = window.refererURL || ''; const referrerURL = window.referrerURL || '';
const search = buildSearchParamsWithLocale(window.location.search); const search = buildSearchParamsWithLocale(window.location.search);
return { return {
url: `/api/v1/widget/messages${search}`, url: `/api/v1/widget/messages${search}`,
@ -9,20 +9,20 @@ const sendMessage = content => {
message: { message: {
content, content,
timestamp: new Date().toString(), timestamp: new Date().toString(),
referer_url: refererURL, referer_url: referrerURL,
}, },
}, },
}; };
}; };
const sendAttachment = ({ attachment }) => { const sendAttachment = ({ attachment }) => {
const { refererURL = '' } = window; const { referrerURL = '' } = window;
const timestamp = new Date().toString(); const timestamp = new Date().toString();
const { file } = attachment; const { file } = attachment;
const formData = new FormData(); const formData = new FormData();
formData.append('message[attachments][]', file, file.name); formData.append('message[attachments][]', file, file.name);
formData.append('message[referer_url]', refererURL); formData.append('message[referer_url]', referrerURL);
formData.append('message[timestamp]', timestamp); formData.append('message[timestamp]', timestamp);
return { return {
url: `/api/v1/widget/messages${window.location.search}`, url: `/api/v1/widget/messages${window.location.search}`,

View file

@ -1,29 +1,48 @@
<template> <template>
<a <div v-if="globalConfig.brandName" class="branding">
v-if="globalConfig.brandName" <a
class="branding" :href="brandRedirectURL"
:href="`${globalConfig.widgetBrandURL}?utm_source=widget_branding`" rel="noreferrer noopener nofollow"
rel="noreferrer noopener nofollow" target="_blank"
target="_blank" class="branding--link"
> >
<img :alt="globalConfig.brandName" :src="globalConfig.logoThumbnail" /> <img :alt="globalConfig.brandName" :src="globalConfig.logoThumbnail" />
<span> <span>
{{ useInstallationName($t('POWERED_BY'), globalConfig.brandName) }} {{ useInstallationName($t('POWERED_BY'), globalConfig.brandName) }}
</span> </span>
</a> </a>
</div>
<div v-else class="brand--alternative" /> <div v-else class="brand--alternative" />
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'; import { mapGetters } from 'vuex';
import globalConfigMixin from 'shared/mixins/globalConfigMixin'; import globalConfigMixin from 'shared/mixins/globalConfigMixin';
import { BUS_EVENTS } from 'shared/constants/busEvents';
export default { export default {
mixins: [globalConfigMixin], mixins: [globalConfigMixin],
data() {
return {
referrerHost: '',
};
},
computed: { computed: {
...mapGetters({ ...mapGetters({
globalConfig: 'globalConfig/get', globalConfig: 'globalConfig/get',
}), }),
brandRedirectURL() {
const baseURL = `${this.globalConfig.widgetBrandURL}?utm_source=widget_branding`;
if (this.referrerHost) {
return `${baseURL}&utm_referrer=${this.referrerHost}`;
}
return baseURL;
},
},
mounted() {
bus.$on(BUS_EVENTS.SET_REFERRER_HOST, referrerHost => {
this.referrerHost = referrerHost;
});
}, },
}; };
</script> </script>
@ -34,22 +53,10 @@ export default {
.branding { .branding {
align-items: center; align-items: center;
color: $color-light-gray;
opacity: 0.9;
display: flex; display: flex;
filter: grayscale(1);
font-size: $font-size-small;
justify-content: center; justify-content: center;
text-align: center;
text-decoration: none;
padding: $space-normal 0 $space-slab; padding: $space-normal 0 $space-slab;
cursor: pointer; text-align: center;
&:hover {
filter: grayscale(0);
opacity: 1;
color: $color-gray;
}
img { img {
margin-right: $space-smaller; margin-right: $space-smaller;
@ -57,6 +64,23 @@ export default {
max-height: $space-slab; max-height: $space-slab;
} }
} }
.branding--link {
color: $color-light-gray;
cursor: pointer;
display: flex;
filter: grayscale(1);
font-size: $font-size-small;
opacity: 0.9;
text-decoration: none;
&:hover {
filter: grayscale(0);
opacity: 1;
color: $color-gray;
}
}
.brand--alternative { .brand--alternative {
padding: $space-slab; padding: $space-slab;
} }