From ca75d57186c16fd18be76d256255121326a194e7 Mon Sep 17 00:00:00 2001 From: Johnson Liang Date: Mon, 25 Mar 2024 14:09:05 +0800 Subject: [PATCH 1/3] feat(liff): add mgp award redirect --- src/liff/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/liff/index.js b/src/liff/index.js index e7077a47..eb38a6c8 100644 --- a/src/liff/index.js +++ b/src/liff/index.js @@ -18,7 +18,17 @@ liff.init({ liffId: LIFF_ID }).then(() => { redirectUri: location.href, }); } else { - dataLayer.push({ userId: liff.getDecodedIDToken().sub }); + const userId = liff.getDecodedIDToken().sub; + dataLayer.push({ userId }); + + const params = new URLSearchParams(location.search); + if (params.get('p') === 'mgp') { + // Replace login with survey + window.location.replace( + `https://www.surveycake.com/s/eqNpB?ssn0=${userId}&ssn58=cofacts` + ); + return; + } // Kickstart app loading; fire assertions new App({ target: document.body }); From 35703f7b29fb1513f4096a57b0b8a377a6c3e933 Mon Sep 17 00:00:00 2001 From: Johnson Liang Date: Mon, 25 Mar 2024 14:45:09 +0800 Subject: [PATCH 2/3] fix: go to external browser in LIFF Otherwise, LINE will display alerts on security --- src/liff/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/liff/index.js b/src/liff/index.js index eb38a6c8..e1a33e8c 100644 --- a/src/liff/index.js +++ b/src/liff/index.js @@ -24,9 +24,7 @@ liff.init({ liffId: LIFF_ID }).then(() => { const params = new URLSearchParams(location.search); if (params.get('p') === 'mgp') { // Replace login with survey - window.location.replace( - `https://www.surveycake.com/s/eqNpB?ssn0=${userId}&ssn58=cofacts` - ); + window.location.href = `https://www.surveycake.com/s/eqNpB?ssn0=${userId}&ssn58=cofacts&openExternalBrowser=1`; return; } From ae57f0aee7223262f60346f9839e5fbff21ecf77 Mon Sep 17 00:00:00 2001 From: Johnson Liang Date: Mon, 25 Mar 2024 15:53:19 +0800 Subject: [PATCH 3/3] fix: use iframe to enhance UX - Avoids opening new browsers - Make URL simple --- src/liff/App.svelte | 2 ++ src/liff/index.js | 10 +--------- src/liff/pages/Mgp.svelte | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 src/liff/pages/Mgp.svelte diff --git a/src/liff/App.svelte b/src/liff/App.svelte index 416e62c8..9d81cd0a 100644 --- a/src/liff/App.svelte +++ b/src/liff/App.svelte @@ -5,6 +5,7 @@ import Comment from './pages/Comment.svelte'; import UserSetting from './pages/UserSetting.svelte'; import Feedback from './pages/Feedback.svelte'; + import Mgp from './pages/Mgp.svelte'; const routes = { article: Article, @@ -12,6 +13,7 @@ setting: UserSetting, comment: Comment, feedback: Feedback, + mgp: Mgp, }; // Send pageview with correct path on each page change. diff --git a/src/liff/index.js b/src/liff/index.js index e1a33e8c..e7077a47 100644 --- a/src/liff/index.js +++ b/src/liff/index.js @@ -18,15 +18,7 @@ liff.init({ liffId: LIFF_ID }).then(() => { redirectUri: location.href, }); } else { - const userId = liff.getDecodedIDToken().sub; - dataLayer.push({ userId }); - - const params = new URLSearchParams(location.search); - if (params.get('p') === 'mgp') { - // Replace login with survey - window.location.href = `https://www.surveycake.com/s/eqNpB?ssn0=${userId}&ssn58=cofacts&openExternalBrowser=1`; - return; - } + dataLayer.push({ userId: liff.getDecodedIDToken().sub }); // Kickstart app loading; fire assertions new App({ target: document.body }); diff --git a/src/liff/pages/Mgp.svelte b/src/liff/pages/Mgp.svelte new file mode 100644 index 00000000..a99d9ab1 --- /dev/null +++ b/src/liff/pages/Mgp.svelte @@ -0,0 +1,18 @@ + + + + + + Cofacts x 第四屆 MyGoPen 謠言惑眾獎 + + +