OmniSegment

埋碼

Table of Contents

TS 新版埋碼

環境設定

  1. 依據商家的設定 TID in omnitag.ts

    const devScriptId = "OA-7b7520dd";
    
  2. 依據商家的 TID 新增 ts file src/user2/

      {
        tid: string;
        defaultHost?: DefaultHostEnum;
        modules: {
          webPopup?: boolean;
          webPush?: boolean;
          aiRecommender?: {
            enabled?: boolean;
            platformType?: AiRecommenderPlatformType;
          };
        };
        actions: (() => Promise<void>)[];
      }
    
  3. 啟動 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
    
  4. 打包部署

      yarn build
    

scripty 設定

埋碼檢查

註冊會員的埋碼

埋碼 check list - 要檢查的 **事件** ? - 所有的事件除了 web 需要檢查之外也含蓋 **mobile** - 每一個頁面 - `init` - `impression` - 這邊會需要注意的是,要有 product 的 id ![](https://i.imgur.com/WLR9cLv.png) - `Search` - 首頁 - `AddToCart` - `clickProduct` - 購物車 - `RemoveFromCart` - `ClickCartIcon` - `ClickCheckout` - `ClickConfirmCheckout` - `Purchase` - 單一商品頁面 - `ViewContent` - `AddToCart` - 相關商品清單 - `clickProduct` - `AddToCart` - 商品清單頁面 - `AddToCart` - `clickProduct` - 這邊需要特別注意的情境 - 新開 new tab 到 單一商品頁面 - 在原本的頁面跳轉 到 單一商品頁面 (這邊可以搭配 omnisegment 顧客頁面的瀏覽紀錄 debug) - 註冊會員 - `CompleteRegistration`

GTM (提交新版本後請客戶上線)

請參考 wiki

埋碼環境 - 新版 ts 埋碼 `omnitag.js` ```html ``` - 舊版 ini 埋碼 `tag.js` ```html ``` - 客戶自行埋碼 `tag-app.js` ```html ```

各系統商

尚峪 SHANG YU

91APP

CYBERBIZ

SHOPLINE

SHOPIFY

QDM

Debug

正式環境下的 debug 方式 ❗️ 下方的方法一跟方法二只能擇一 1. 方法一:使用本地端打包後的正式環境版 ini 檔 (u/OA-OOXX.ini) - 在瀏覽器開發者工具中的設定啟用 本地覆寫 - ![](https://i.imgur.com/Xs30S3n.png) - 開啟瀏覽器開發者工具的 `網路` 頁籤尋找正式環境的埋碼腳本請求然後在來源面板中開啟 - ![截圖 2023-02-08 下午7 02 50](https://user-images.githubusercontent.com/6936817/217512128-7c9d5fbd-67fc-4837-8e68-0d7f726f825a.png) - 開啟瀏覽器開發者工具找到 `原始碼` -> `檔案` - 尋找正式環境的埋碼腳本 e.g `https://omnitag.omniscientai.com` -> `tag.js?id=OA-OOXX`. - 點選 `儲存以覆寫` - 截圖 2022-10-06 下午12 29 45 - 接著在 `覆寫` 頁籤下可以找到剛剛的檔案 - 截圖 2022-10-06 下午12 36 34 - 在終端機環境下在 `compile.sh` 所在資料夾下執行 `./compile.sh rd` - 打包完的檔案會在 `/omnitag/assets/tagDebug.bundle.js` - 支援指定 ini 檔 `./compile.sh rd 3d6f1ff4` - 把檔案內容複製貼上到 `覆寫` 頁籤下的檔案後存檔即可,也可在 vscode 中處理 - 打包完的檔案會在 `/omnitag/assets/tagDebug.bundle.js` - ❗️ 更改 ini 不需要再重新覆寫,reload 即可同步更新 - vscode 示意圖: ![截圖 2023-02-09 下午3 00 57](https://user-images.githubusercontent.com/6936817/217741075-d798044c-83d8-4bb9-a7c1-b9e88a98f3bb.png) 2. 方法二:使用本地端打包後的開發環境版 ini 檔 (src/user/OA-OOXX.ini) - 在 local 啟動專案後在 客戶的網頁上 block Request URL: `https://omnitag.omniscientai.com/tag.js?id=OA-xxxxx` - 透過 Chrome extension - [HTTP Request Blocker](https://chrome.google.com/webstore/detail/http-request-blocker/eckpjmeijpoipmldfbckahppeonkoeko/related?hl=en) block `*://omnitag.omniscientai.com/*` / `*://usergram.omniscientai.com/*.` ![](https://i.imgur.com/nw5jMad.png) - 透過擴充功能彈性的在我們想要的網站開啟阻擋清單 ![](https://i.imgur.com/0CAr9uW.png) - 手動 block request ![截圖 2023-02-08 下午3 57 03](https://user-images.githubusercontent.com/6936817/217516610-3999d18f-ac56-4c92-ba7f-82e36d9237e9.png)

INI 舊版埋碼

開發前的環境建置 #### 設定 `ini file` - 依據商家的 TID 新增 ini file in `src/user/` - tagId 按照商家的 TID 設置 ```ini tagId=OA-XXXXXXXX #商家的 TID ``` - `tag_gtag_id`, `tag_gtag_gaId` 不用改 ```ini tag_gtag_id="GTM-TW79K5B" tag_gtag_gaId="G-C2HNKLYPCW" ``` #### 設定 `tag_dev.js` - 在 tag_dev.js 中的 iniUrl,init 的檔名對應上面的 `tagId`。 ‼️ 這邊 iniUrl 的 port 須對應到 `scripty` 上使用的 port,以及 package.json 上 `yarn start` 的 port ``` const iniUrl = "http://localhost:7000/src/user/OA-1597cbff-2.ini"; ``` - `defaultMpHost` 為收集埋碼事件的 server, 這裡的 `tagId` 為 omnisegment 中帳號所屬的組織 id, 在 omnisegment 中某個帳號只能看到該組織底下的事件收集資料, 可在 `http://localhost/ma/setting/?type=TRACKING` 中查看帳號所屬的組織 id . ```js { path: ["defaultMpHost"], value: "http://localhost:8000", // localhost 必須用 http }, { path: ["tagId"], value: "OA-c19eb6", // 以local為例,預設是測試管理者帳號admin@RUB的TID }, ``` ![截圖 2022-07-14 下午4 44 58](https://user-images.githubusercontent.com/6936817/178942204-a68e5ade-8738-4509-97f0-dc82ec7bd635.png)

客戶自行埋碼環境

開發前的環境建置 #### 設定 app.js - 直接在下方指定參數 ```js { path: ["defaultMpHost"], value: takeSettingWithEnv({ development: DefaultHostEnum.DEV, production: DefaultHostEnum.TW, }), }, { path: ["tagId"], value: takeSettingWithEnv({ development: "OA-c19eb6", production: i13nData.tagId, }), }, { path: ["aiRecommender"], value: takeSettingWithEnv({ development: { enabled: true, platformType: AiRecommenderPlatformTypeEnum["91App"], }, production: i13nData.aiRecommender, }), }, ```

推薦商品版位網頁內嵌開發

開發環境設置 ### OS 環境設置 - 開啟 `Module Permission`: `ProductEmbed` - 打開後登入 OS http://localhost/ma/setting/?&type=WEBPOPUP_EMBED 並打開設定 - 記得也要開啟帳號進階權限下的 `可控管渠道發送` http://localhost/ma/setting/?&type=PERMISSION - 完成後即可在 http://localhost/ma/edm/webpopup_embed 下編輯模板 - 目前有三個預設常態性模板分別代表 (首頁、商品頁、結帳頁),編入編輯並啟用即可讓推薦商品內嵌模板 API 正常取得資料 (http://localhost/ma_cms/get-all-routers/?species=product_embed) - 同一時間透過 API 取得的模板最多兩個,預設跟限定期間模板 - abtest 只在限定期間模板下可以設定 - 推薦商品內嵌設定關閉或沒有權限下 API 會報 403 - 根據是否取得模板資料、推薦商品內嵌設定開關與權限決定顯示與否 (限定模板 -> 預設模板 -> 不顯示) - 後端會回傳時間範圍內的模板,前端不額外判斷時間範圍 ### omnitag 功能開關 - 客戶自行埋碼環境: app.js ```js client(i13nData, (configs, cb) => cb(configs, [ ...getOverWrite(), { path: ["defaultMpHost"], value: takeSettingWithEnv({ development: DefaultHostEnum.DEV, production: DefaultHostEnum.TW, }), }, { path: ["tagId"], value: takeSettingWithEnv({ development: "OA-c19eb6", production: i13nData.tagId, }), }, { path: ["aiRecommender"], value: takeSettingWithEnv({ development: { enabled: true, platformType: AiRecommenderPlatformTypeEnum["91App"], }, production: i13nData.aiRecommender, }), }, ]) ); ``` - ini 檔埋碼環境: OA-123.js ```ini ; User: bebittech shopline test https://bebittech.shopline.test.com/ ; type: Shopline ; Tags currencyCode=TWD tagId=OA-123 ... aiRecommender_enabled=true aiRecommender_platformType=shopline ... ``` - ts 檔埋碼環境: OA-123.ts ```js function getClientConfig(): ClientConfig { return { tid: "OA-123", modules: { webPopup: true, webPush: false, aiRecommender: { enabled: true, platformType: AiRecommenderPlatformTypeEnum.Shopline, }, }, actions: [ setUid, productImpression, ... ], }; } ``` ### 使用假資料 - 客戶自行埋碼環境: tagBase.js - ini 檔埋碼環境: tag_dev.js - ts 檔埋碼環境: omnitag.js ``` if (aiRecommender?.enabled) { aiRecommenderPlugin.init({ hostDomain: defaultMpHost, config: { platformType: aiRecommender?.platformType, tagId, clientId: getClientId(), userId: uid, demo: true, }, }); } ``` ### 參考資料: [推薦商品版位網頁內嵌](https://github.com/beBit-tech/omnitag/wiki/%E6%8E%A8%E8%96%A6%E5%95%86%E5%93%81%E7%89%88%E4%BD%8D%E7%B6%B2%E9%A0%81%E5%85%A7%E5%B5%8C)

測試 webpopup

開發測試注意事項 1. tid 要設定得跟 OS 開發環境上的一樣 ![](https://i.imgur.com/H7DDmP5.png) 2. 檢查測試網站的 session storage ![](https://i.imgur.com/b5WctqA.png) - 當有舊的 cache 存在時,進入 storage 點擊 clear site data ![](https://i.imgur.com/sy11tYp.png)

Inspect popup

在 console 輸入 inspectPopup(popup id) 可調出 popup 觸發條件判定結果列表,並進入 debugger 模式,可存取諸如 context, uidcid 等。

Troubleshooting

i13n

Port 7000 被佔用 ?

Local API CORS issue

SHOPLINE 平台本身有使用 Sentry,開發時有時會因為 Sentry 導致 local API 有 CORS issue。這時可以在 HTTP Request Blocker 上可加入 *://*.sentry-cdn.com/*

截圖 2023-09-11 上午11 47 18

如何手動發送 impressions through pageView (SPA)

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);