依據商家的設定 TID in omnitag.ts
const devScriptId = "OA-7b7520dd";
依據商家的 TID 新增 ts file src/user2/
{
tid: string;
defaultHost?: DefaultHostEnum;
modules: {
webPopup?: boolean;
aiRecommender?: {
enabled?: boolean;
platformType?: AiRecommenderPlatformType;
};
};
actions: (() => Promise<void>)[];
}
啟用 corepack
如有使用其他方式安裝yarn
如brew
(which yarn
看到的路徑會像這樣 /opt/homebrew/bin/yarn
) 請移除後改用此方式安裝
corepack enable
啟動 dev-serve
yarn dev
entries
http://localhost:7001/[entry]
omnitag.js
tag-app.js
tag.js
tagDev.js
tag-poc-jp.js
tag-jp.js
omni-webpush.js
打包部署
yarn build
單元測試
手動:
yarn test
監控模式: 測試檔案或者測試檔案中引用的模組有更動會自動重跑 (note. commonJS require("xxx/yyy")
目前還不支援,請使用 es6
模組引入方式 )
yarn test:watch
example output
$ node mocha-watch
-- Running the modified tests in dependency tree --
./node_modules/.bin/mocha src/__tests__/filterWebview.test.js
...
filterWebview
✔ org enable web popup in webview
✔ org disable web popup in webview but it's not in webview
✔ org disable web popup in webview and it's in webview
3 passing (2ms)
-- Running the modified tests in dependency tree --
./node_modules/.bin/mocha src/__tests__/tagWebTest.js
...
Test tag
✔ should dispatched i13n state with expected configs (107ms)
Found duplicate omnitag: undefined
✔ should warn if there are duplicated tags
✔ should called fetchAPIConfig with tagId
3 passing (142ms)
-- Running the modified tests --
./node_modules/.bin/mocha src/plugins/__tests__/querySelectorUtils.test.js
...
Test utils: querySelectorWithMatchOrder etswerstr
✔ should get dom with simple selector
✔ should get dom with native selector list
✔ should get dom with custom selector list match by comma order
✔ should get dom with custom selector list match by reverse dom order
✔ should not get dom with element visible filter
✔ should get dom with element visible filter
✔ should get dom with mutation observer (1006ms)
7 passing (1s)
Create/Edit Script 中
Name
可以隨意填,自己好記好區別即可Javascript Code
部分按照環境填入以下代碼
ts 版本環境
(function () {
var doc = document;
var el = doc.createElement("script");
el.src = "http://localhost:7001/omnitag.js";
var s = doc.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})();
ini 版本環境
(function () {
var doc = document;
var el = doc.createElement("script");
el.src = "http://localhost:7001/tagDev.js";
var s = doc.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})();
客戶埋碼版本環境
(function () {
var doc = document;
var el = doc.createElement("script");
el.type = "text/javascript";
el.async = true;
el.src = "http://localhost:7001/tag-app.js";
var s = doc.getElementsByTagName("script")[0];
s.parentNode.insertBefore(el, s);
})();
Run script if [URL] [Contains] Following input
這邊填入商家的網址Trigger
選擇 Automatically [On Page Load]
後按下 Create/Update Script
在店家網址完成註冊後進入 omnisegment 顧客頁面點擊會員
uid 採用 GTM 自定義變數方式帶入,而 GTM 變數則可在該 GTM 中搜尋,可參考以下方式:
Omnisegment_MID
/ cookie_MID
MID
即可使用該變數名稱// enable WebPopup
<script>
window.i13nData = {
tagId: "[Your-TID]",
uid: , // e.g.
disableHandleImpression: true,
};
</script>
<script async src="https://omnitag.omniscientai.com/tag-app.js"></script>
// enable WebPopup and AI Embedded
<script>
window.i13nData = {
tagId: "[Your-TID]",
uid: , // e.g.
disableHandleImpression: true,
aiRecommender: {
enabled: true,
platformType: "91app"
}
};
</script>
<script async src="https://omnitag.omniscientai.com/tag-app.js"></script>
MID
,uid 相關的條件及模組也無法適用,像是 WebPopup 設定中的「會員登入」/「Line 狀態」及特定 WebPopup 類別 Line 綁定模組。Bogus Gateway
1
交易成功、2
交易失敗、3
支付商錯誤111
12/34
在 console 輸入 inspectPopup(popup id)
可調出 popup 觸發條件判定結果列表,並進入 debugger 模式,可存取諸如 context
, uid
、cid
等。
在 console 輸入 omnitagPageviewHistoryHelper
及可使用提供的 helper function
push(url, title)
新增 dataupdate(id, key, value)
更新 tableremove(id)
移除 tablegetAll()
取得所有資料getByPastDays(days)
取得過去 n 天資料print(table or db object)
顯示資料help()
取得相關使用說明i13n.dispatch
的型別提示,可參考下面範例。其他尚未有型別定義的請使用 any
import { type Dispatch } from "../types";
const { dispatch, getUserId }: { dispatch: Dispatch; getUserId: any } = window.i13n;
如果用 MacOS 的話很可能預設 AirPlay 開啟並佔用 port 7000,可以去關掉 AirPlay
[Why is Control Center on Monterey … | Apple Developer Forums](https://developer.apple.com/forums/thread/682332) |
SHOPLINE 平台本身有使用 Sentry,開發時有時會因為 Sentry 導致 local API 有 CORS issue。這時可以在 HTTP Request Blocker 上可加入 *://*.sentry-cdn.com/*
:
i13n pageView 預設為自動發送,如果 impressions 為非同步取得則可能發生 race condition。目前新客戶在 detail impression 串接上已建議採用較彈性的 ViewContent
,但 list impressions 如仍有需求場景可在取得資料後執行:
// 延遲執行避免與 BaseI13nStore 內部初始化階段發生衝突
setTimeout(() => {
dispatch({ i13nPage: { impressions } }); // update store
dispatch("view"); // send beacon
}, 100);
*如果希望關閉自動發送 pageView 機制,手動控制每一頁的送出時機點,需藉由控制 ClientConfig - disableHandleImpression
來實現:
async function getClientConfig(): Promise<ClientConfig> {
return {
tid: "{tid}",
waitForUid,
actions,
disableHandleImpression: true, // 為 true 時不會發送 pageView
};
}
export default getClientConfig();
// 取得資料後
setTimeout(() => {
// 發送前設為 false 才能發送 pageView
dispatch({ disableHandleImpression: false, i13nPage: { impressions } });
dispatch("view");
}, 100);