Skip to content

Commit

Permalink
Merge pull request #86 from aplijobs/fix/referral
Browse files Browse the repository at this point in the history
Fix ref references with referral full name
  • Loading branch information
cmm-apli authored May 18, 2023
2 parents 58c86c9 + fbfe5f6 commit 3b44e23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/javascript/packs/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const runSDK = ({ baseUrl, websiteToken, referral }) => {
}

window.$chatwoot = {
ref: referral,
referral: referral,
baseUrl,
hasLoaded: false,
hideMessageBubble: chatwootSettings.hideMessageBubble || false,
Expand Down Expand Up @@ -168,7 +168,7 @@ const runSDK = ({ baseUrl, websiteToken, referral }) => {
iframe.src = IFrameHelper.getUrl({
baseUrl: window.$chatwoot.baseUrl,
websiteToken: window.$chatwoot.websiteToken,
ref: window.$chatwoot.ref
referral: window.$chatwoot.referral
});

window.$chatwoot.resetTriggered = true;
Expand Down
12 changes: 8 additions & 4 deletions app/javascript/sdk/IFrameHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,22 @@ const updateCampaignReadStatus = () => {
};

export const IFrameHelper = {
getUrl({ baseUrl, websiteToken, ref }) {
return `${baseUrl}/widget?website_token=${websiteToken}&ref=${ref}`;
getUrl({ baseUrl, websiteToken, referral }) {
let ref = '';
if (referral) {
ref = `&referral=${referral}`
}
return `${baseUrl}/widget?website_token=${websiteToken}${ref}`;
},
createFrame: ({ baseUrl, websiteToken, ref }) => {
createFrame: ({ baseUrl, websiteToken, referral }) => {
if (IFrameHelper.getAppFrame()) {
return;
}

loadCSS();
const iframe = document.createElement('iframe');
const cwCookie = Cookies.get(`cw_conversation_${websiteToken}`);
let widgetUrl = IFrameHelper.getUrl({ baseUrl, websiteToken, ref });
let widgetUrl = IFrameHelper.getUrl({ baseUrl, websiteToken, referral });
if (cwCookie) {
widgetUrl = `${widgetUrl}&cw_conversation=${cwCookie}`;
}
Expand Down
8 changes: 6 additions & 2 deletions app/javascript/widget/store/modules/conversation/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const actions = {
const [message = {}] = messages;
commit('pushMessageToConversation', message);
dispatch('conversationAttributes/getAttributes', {}, { root: true });
const ref = new URLSearchParams(window.location.search).get('referral');
if (ref) {
await setCustomAttributes({"ref": ref});
}
} catch (error) {
captureSentryException(error);
} finally {
Expand Down Expand Up @@ -100,8 +104,8 @@ export const actions = {
commit('conversation/setMetaUserLastSeenAt', lastSeen, { root: true });
commit('setMessagesInConversation', formattedMessages);
commit('setConversationListLoading', false);
const ref = new URLSearchParams(window.location.search).get('ref');
if(ref) {
const ref = new URLSearchParams(window.location.search).get('referral');
if (ref) {
await setCustomAttributes({"ref": ref});
}
} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion app/javascript/widget/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export default {
},
methods: {
startConversation() {
this.$store.dispatch('conversation/createConversation', {});
const ref = new URLSearchParams(window.location.search).get('referral');
if (ref) {
this.$store.dispatch('conversation/createConversation', {});
}
if (this.preChatFormEnabled && !this.conversationSize) {
return this.replaceRoute('prechat-form');
}
Expand Down

0 comments on commit 3b44e23

Please sign in to comment.