diff --git a/package-lock.json b/package-lock.json index c208473..44edbdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "review-bookmark", - "version": "3.0.2", + "version": "3.0.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 05855af..0f23708 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "review-bookmark", - "version": "3.0.3", + "version": "3.0.4", "description": "A bookmark manager for Chrome.", "author": "ETY001 ", "license": "MIT", @@ -15,7 +15,7 @@ "build-firefox": "cross-env NODE_ENV=production BROWSER_PROTO=firefox webpack --hide-modules", "build:dev": "cross-env NODE_ENV=development BROWSER_PROTO=chrome webpack --hide-modules", "build-firefox:dev": "cross-env NODE_ENV=development BROWSER_PROTO=firefox webpack --hide-modules", - "build-zip": "node scripts/build-zip.js", + "build-zip": "find dist | xargs touch -mt 202002110000 && cd dist && zip -r -X dist.zip . && mv dist.zip ..", "watch": "npm run build -- --watch", "watch-firefox": "npm run build-firefox -- --watch", "watch:dev": "cross-env HMR=true npm run build:dev -- --watch", diff --git a/src/background.js b/src/background.js index 4b58a02..ec7e902 100644 --- a/src/background.js +++ b/src/background.js @@ -7,6 +7,7 @@ global.browser = require('webextension-polyfill'); const isFirefox = navigator.userAgent.toUpperCase().indexOf('Firefox') ? true : false; const isChrome = window.navigator.userAgent.indexOf('Chrome') !== -1; +const isEdge = navigator.userAgent.indexOf('Edg') !== -1; //清空之前版本的数据 if (window.localStorage.curt_index === undefined) { @@ -14,6 +15,8 @@ if (window.localStorage.curt_index === undefined) { indexedDB.deleteDatabase('bookmarks'); } +const debug = process.env.NODE_ENV === 'development'; + // 检测新标签页,控制迷你和full版本 chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (isChrome) { @@ -34,10 +37,12 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { } } } - if (tab.url === 'edge://newtab/') { - if (store.getters.config.mini === false) { - const url = chrome.runtime.getURL('tab/tab.html'); - chrome.tabs.update(tabId, { url }); + if (isEdge) { + if (tab.url === 'edge://newtab/') { + if (store.getters.config.mini === false) { + const url = chrome.runtime.getURL('tab/tab.html'); + chrome.tabs.update(tabId, { url }); + } } } }); @@ -68,16 +73,17 @@ const GetUid = { const uid = GetUid.get(); //google analytics -let currentVersion = '3_0_3'; +let currentVersion = '3_0_4'; if (isChrome) { currentVersion = `chrome_${currentVersion}`; -} -if (isFirefox) { +} else if (isFirefox) { currentVersion = `firefox_${currentVersion}`; +} else if (isEdge) { + currentVersion = `edge_${currentVersion}`; } const gaID = 'UA-64832923-4'; -const gaObj = new GA(gaID, uid); -function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = '') { +const gaObj = new GA(gaID, uid, debug); +function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = 1) { if (store.getters.config.ga === false) return; gaObj.ga('event', eventCategory, eventAction, eventLabel, eventValue); } @@ -253,7 +259,7 @@ chrome.bookmarks.onRemoved.addListener((id, removeInfo) => { // 安装/升级检测 chrome.runtime.onInstalled.addListener(detail => { if (detail.reason == 'update') { - sendEvent(currentVersion, 'update_extension', uid, ''); + sendEvent(currentVersion, 'update_extension', uid, 1); // 弹出推广页面 window.open('https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324'); return; @@ -268,7 +274,7 @@ chrome.runtime.onInstalled.addListener(detail => { ); } if (detail.reason === 'install') { - sendEvent(currentVersion, 'install_extension', uid, ''); + sendEvent(currentVersion, 'install_extension', uid, 1); console.log('installed'); // 初始化数据 BookmarkLib.init(); diff --git a/src/libs/GA.js b/src/libs/GA.js index 9d5c8b4..b5d666d 100644 --- a/src/libs/GA.js +++ b/src/libs/GA.js @@ -1,8 +1,8 @@ export class GA { - constructor(ua, cid) { + constructor(ua, cid, debug = false) { this.ua = ua; this.cid = cid; // client id - this.gaApi = 'https://www.google-analytics.com/collect'; + this.gaApi = debug ? 'https://www.google-analytics.com/debug/collect' : 'https://www.google-analytics.com/collect'; this.version = '1'; } ga(t, ...items) {