Skip to content

Commit fbfd7f4

Browse files
authored
Merge pull request #11 from ety001/3.0.2
3.0.2
2 parents d0650b2 + 4a385b3 commit fbfd7f4

11 files changed

+141
-91
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "review-bookmark",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "A bookmark manager for Chrome.",
55
"author": "ETY001 <[email protected]>",
66
"license": "MIT",

src/_locales/en/messages.json

+6
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,11 @@
130130
},
131131
"clear_block_list": {
132132
"message": "Clear List"
133+
},
134+
"ga": {
135+
"message": "Whether to enable Data Analyzes? This will help author improve the extension's experience."
136+
},
137+
"enable": {
138+
"message": "Enable"
133139
}
134140
}

src/_locales/zh_CN/messages.json

+6
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,11 @@
130130
},
131131
"clear_block_list": {
132132
"message": "清空列表"
133+
},
134+
"ga": {
135+
"message": "是否允许作者统计数据以此提升使用体验"
136+
},
137+
"enable": {
138+
"message": "激活"
133139
}
134140
}

src/background.js

+30-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import store from './store';
22
import * as types from './store/mutation-types';
33
import * as BookmarkLib from './libs/BookmarkLib';
4+
import { GA } from './libs/GA';
45

56
global.browser = require('webextension-polyfill');
67

@@ -35,29 +36,6 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
3536
}
3637
});
3738

38-
//google analytics
39-
const currentVersion = '3_0_1';
40-
const gaID = 'UA-64832923-4';
41-
(function(i, s, o, g, r, a, m) {
42-
i['GoogleAnalyticsObject'] = r;
43-
(i[r] =
44-
i[r] ||
45-
function() {
46-
(i[r].q = i[r].q || []).push(arguments);
47-
}),
48-
(i[r].l = 1 * new Date());
49-
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
50-
a.async = 1;
51-
a.src = g;
52-
m.parentNode.insertBefore(a, m);
53-
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
54-
ga('create', gaID, 'auto');
55-
ga('set', 'checkProtocolTask', function() {});
56-
ga('require', 'displayfeatures');
57-
function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = '') {
58-
ga('send', 'event', eventCategory, eventAction, eventLabel, eventValue);
59-
}
60-
6139
// 生成uid
6240
const RandomStr = function(len) {
6341
len = len || 32;
@@ -77,13 +55,32 @@ const GetUid = {
7755
var d = new Date();
7856
var uid = RandomStr() + d.getSeconds() + d.getMinutes() + d.getMilliseconds();
7957
window.localStorage.uid = uid;
80-
sendEvent(currentVersion, 'create_user', uid);
8158
}
8259
return uid;
8360
},
8461
};
8562
const uid = GetUid.get();
8663

64+
//google analytics
65+
let currentVersion = '3_0_2';
66+
if (isChrome) {
67+
currentVersion = `chrome_${currentVersion}`;
68+
}
69+
if (isFirefox) {
70+
currentVersion = `firefox_${currentVersion}`;
71+
}
72+
const gaID = 'UA-64832923-4';
73+
const gaObj = new GA(gaID, uid);
74+
function sendEvent(eventCategory, eventAction, eventLabel = '', eventValue = '') {
75+
if (store.getters.config.ga === false) return;
76+
gaObj.ga('event', eventCategory, eventAction, eventLabel, eventValue);
77+
}
78+
// dh -- Document hostname, dp -- Page, dt -- Title
79+
function sendPageview(dp, dh = '', dt = '') {
80+
if (store.getters.config.ga === false) return;
81+
gaObj.ga('pageview', dh, dp, dt);
82+
}
83+
8784
//数据初始化
8885
BookmarkLib.init();
8986

@@ -100,6 +97,7 @@ chrome.runtime.onConnect.addListener(function(port) {
10097
return;
10198
}
10299
const bmForFull = BookmarkLib.getBookmark();
100+
sendPageview('/full_mode_page');
103101
sendEvent(currentVersion, 'getbookmark_from_full', 'get_bookmark_' + uid, JSON.stringify({ uid, bmForFull }));
104102
port.postMessage({ ctype: ctype, cdata: bmForFull });
105103
break;
@@ -109,6 +107,7 @@ chrome.runtime.onConnect.addListener(function(port) {
109107
return;
110108
}
111109
const bmForMini = BookmarkLib.getBookmark();
110+
sendPageview('/mini_mode_notification');
112111
sendEvent(currentVersion, 'getbookmark_from_mini', 'get_bookmark_' + uid, JSON.stringify({ uid, bmForMini }));
113112
port.postMessage({
114113
ctype,
@@ -146,6 +145,7 @@ chrome.runtime.onConnect.addListener(function(port) {
146145
break;
147146
case 'getbookmark_menu':
148147
BookmarkLib.getBookmarkMenu(menu => {
148+
sendPageview('/bookmark_manager_page');
149149
sendEvent(currentVersion, 'getbookmark_menu', 'getbookmark_menu_' + uid, JSON.stringify({ uid }));
150150
port.postMessage({ ctype, cdata: menu });
151151
});
@@ -180,6 +180,7 @@ chrome.runtime.onConnect.addListener(function(port) {
180180
});
181181
break;
182182
case 'get_config':
183+
sendPageview('/popup');
183184
sendEvent(currentVersion, 'get_config', 'get_config_' + uid, JSON.stringify({ uid, config: store.getters.config }));
184185
port.postMessage({ ctype, cdata: store.getters.config });
185186
break;
@@ -191,6 +192,7 @@ chrome.runtime.onConnect.addListener(function(port) {
191192
random: cdata.random,
192193
frequency: cdata.frequency,
193194
currentNotifyLocation: cdata.currentNotifyLocation,
195+
ga: cdata.ga,
194196
});
195197
port.postMessage({ ctype, cdata: true });
196198
break;
@@ -203,6 +205,7 @@ chrome.runtime.onConnect.addListener(function(port) {
203205
});
204206
break;
205207
case 'get_block_list':
208+
sendPageview('/block_list_page');
206209
sendEvent(currentVersion, 'get_block_list', 'get_block_list_' + uid, JSON.stringify({ uid }));
207210
BookmarkLib.getBlockList(blockedBookmarks => {
208211
port.postMessage({ ctype, cdata: blockedBookmarks });
@@ -245,6 +248,9 @@ chrome.bookmarks.onRemoved.addListener((id, removeInfo) => {
245248
chrome.runtime.onInstalled.addListener(detail => {
246249
if (detail.reason == 'update') {
247250
sendEvent(currentVersion, 'update_extension', uid, '');
251+
// 弹出推广页面
252+
window.open('https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324');
253+
return;
248254
chrome.notifications.create(
249255
{
250256
type: 'basic',
@@ -254,8 +260,6 @@ chrome.runtime.onInstalled.addListener(detail => {
254260
},
255261
function(notification_id) {}
256262
);
257-
// 弹出推广页面
258-
window.open('https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324');
259263
}
260264
if (detail.reason === 'install') {
261265
sendEvent(currentVersion, 'install_extension', uid, '');

src/libs/ChromeStorage.js

-60
This file was deleted.

src/libs/GA.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export class GA {
2+
constructor(ua, cid) {
3+
this.ua = ua;
4+
this.cid = cid; // client id
5+
this.gaApi = 'https://www.google-analytics.com/collect';
6+
this.version = '1';
7+
}
8+
ga(t, ...items) {
9+
let payload = `v=${this.version}&tid=${this.ua}&cid=${this.cid}`;
10+
let params = [];
11+
switch (t) {
12+
case 'pageview': // Pageview hit type
13+
// dh -- Document hostname
14+
// dp -- Page
15+
// dt -- Title
16+
params = ['dh', 'dp', 'dt'];
17+
break;
18+
case 'event':
19+
// ec -- Event Category. Required
20+
// ea -- Event Action. Required
21+
// el -- Event label.
22+
// ev -- Event value.
23+
params = ['ec', 'ea', 'el', 'ev'];
24+
}
25+
if (params === []) return;
26+
payload = `${payload}&t=${t}`;
27+
items.forEach((v, i) => {
28+
payload = `${payload}&${params[i]}=${encodeURIComponent(v)}`;
29+
});
30+
const request = new XMLHttpRequest();
31+
request.open('POST', this.gaApi, true);
32+
request.send(payload);
33+
}
34+
}

src/manifest.firefox.json

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "__MSG_appname__",
3+
"description": "__MSG_appdesc__",
4+
"version": null,
5+
"manifest_version": 2,
6+
"default_locale": "en",
7+
"author": "ETY001",
8+
"homepage_url": "https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324",
9+
"icons": {
10+
"16": "icons/icon-16.png",
11+
"19": "icons/icon-19.png",
12+
"38": "icons/icon-38.png",
13+
"48": "icons/icon-48.png",
14+
"128": "icons/icon-128.png"
15+
},
16+
"browser_action": {
17+
"default_title": "__MSG_appname__",
18+
"default_popup": "popup/popup.html"
19+
},
20+
"background": {
21+
"scripts": ["background.js"]
22+
},
23+
"content_scripts": [
24+
{
25+
"matches": ["*://*/*"],
26+
"css": ["content-script/content-script.css"],
27+
"js": ["content-script/cs-init.js", "content-script/content-script.js"],
28+
"run_at": "document_end"
29+
}
30+
],
31+
"web_accessible_resources": ["tab/tab.html", "fonts/*", "bookmark/bookmark.html"],
32+
"permissions": ["notifications", "bookmarks", "tabs", "storage", "unlimitedStorage", "https://www.google-analytics.com/"]
33+
}

src/manifest.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"run_at": "document_end"
2929
}
3030
],
31-
"content_security_policy": "script-src 'self' https://www.google-analytics.com; object-src 'self'",
3231
"web_accessible_resources": ["tab/tab.html", "fonts/*", "bookmark/bookmark.html"],
33-
"permissions": ["notifications", "bookmarks", "tabs", "background", "storage", "unlimitedStorage"]
32+
"permissions": ["notifications", "bookmarks", "tabs", "background", "storage", "unlimitedStorage", "https://www.google-analytics.com/"]
3433
}

src/popup/App.vue

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
<template>
22
<div>
33
<el-row class="config-box" v-if="formData !== null">
4-
<el-col :span="24">
4+
<el-col :span="24" v-if="ga === false">
5+
<h4>{{ 'ga' | lang }}</h4>
6+
<el-form>
7+
<el-form-item>
8+
<el-button type="primary" @click="enableGa()">{{ 'confirm_btn' | lang }}</el-button>
9+
<el-button type="warning" @click="cancelGa()">{{ 'cancel_btn' | lang }}</el-button>
10+
</el-form-item>
11+
</el-form>
12+
</el-col>
13+
<el-col :span="24" v-if="ga === true">
514
<el-form ref="form1" :rules="rules" :model="formData" label-position="left" label-width="140px" @submit.native.prevent>
615
<el-form-item :label="'switch' | lang" prop="status">
716
<el-switch v-model="formData.status"></el-switch>
@@ -20,6 +29,12 @@
2029
<el-option v-for="(item, idx) in notifyLocation" :key="idx" :label="item.name" :value="item.val"></el-option>
2130
</el-select>
2231
</el-form-item>
32+
<el-form-item label="" prop="ga" size="mini" label-width="0">
33+
<el-checkbox-group v-model="formData.ga">
34+
<el-checkbox :label="'ga' | lang" name="ga"></el-checkbox>
35+
</el-checkbox-group>
36+
</el-form-item>
37+
2338
<el-form-item>
2439
<el-button type="primary" @click="save('form1')">{{ 'save' | lang }}</el-button>
2540
<el-button type="warning" @click="blockManager()">{{ 'block_manager' | lang }}</el-button>
@@ -43,6 +58,7 @@ export default {
4358
};
4459
return {
4560
formData: null,
61+
ga: false,
4662
notifyLocation: [
4763
{
4864
name: this.getLang('top_right'),
@@ -65,6 +81,7 @@ export default {
6581
status: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
6682
mini: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
6783
random: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
84+
ga: [{ type: 'boolean', message: 'need boolean', trigger: 'change' }],
6885
frequency: [{ type: 'integer', message: this.getLang('need_integer'), trigger: 'blur' }],
6986
currentNotifyLocation: [{ validator: validateNotifyPosition, trigger: 'change' }],
7087
},
@@ -76,6 +93,13 @@ export default {
7693
if (!val) return '';
7794
return chrome.i18n.getMessage(val);
7895
},
96+
enableGa() {
97+
this.formData.ga = true;
98+
this.port.postMessage({ ctype: 'save_config', cdata: this.formData });
99+
},
100+
cancelGa() {
101+
this.ga = true;
102+
},
79103
save(formName) {
80104
this.$refs[formName].validate(valid => {
81105
if (!valid) {
@@ -109,6 +133,7 @@ export default {
109133
type: 'success',
110134
message: this.getLang('save_success'),
111135
});
136+
this.ga = true;
112137
break;
113138
case 'get_config':
114139
this.formData = {
@@ -117,7 +142,9 @@ export default {
117142
random: msg.cdata.random,
118143
frequency: msg.cdata.frequency,
119144
currentNotifyLocation: msg.cdata.currentNotifyLocation,
145+
ga: msg.cdata.ga,
120146
};
147+
this.ga = msg.cdata.ga;
121148
break;
122149
}
123150
});

src/store/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export default new Vuex.Store({
2020
random: true, // 随机展示
2121
frequency: 5, // mini 模式展示频度
2222
currentNotifyLocation: 'top-right', // 当前 Mini 提醒框位置
23+
ga: false, // Google Analytics Status
2324
},
2425
frequencyCounter: 0, // mini模式展示频度计数器
2526
waitingBookmarks: [], // 所有待提醒书签

0 commit comments

Comments
 (0)