1
1
import store from './store' ;
2
2
import * as types from './store/mutation-types' ;
3
3
import * as BookmarkLib from './libs/BookmarkLib' ;
4
+ import { GA } from './libs/GA' ;
4
5
5
6
global . browser = require ( 'webextension-polyfill' ) ;
6
7
@@ -35,29 +36,6 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
35
36
}
36
37
} ) ;
37
38
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
-
61
39
// 生成uid
62
40
const RandomStr = function ( len ) {
63
41
len = len || 32 ;
@@ -77,13 +55,32 @@ const GetUid = {
77
55
var d = new Date ( ) ;
78
56
var uid = RandomStr ( ) + d . getSeconds ( ) + d . getMinutes ( ) + d . getMilliseconds ( ) ;
79
57
window . localStorage . uid = uid ;
80
- sendEvent ( currentVersion , 'create_user' , uid ) ;
81
58
}
82
59
return uid ;
83
60
} ,
84
61
} ;
85
62
const uid = GetUid . get ( ) ;
86
63
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
+
87
84
//数据初始化
88
85
BookmarkLib . init ( ) ;
89
86
@@ -100,6 +97,7 @@ chrome.runtime.onConnect.addListener(function(port) {
100
97
return ;
101
98
}
102
99
const bmForFull = BookmarkLib . getBookmark ( ) ;
100
+ sendPageview ( '/full_mode_page' ) ;
103
101
sendEvent ( currentVersion , 'getbookmark_from_full' , 'get_bookmark_' + uid , JSON . stringify ( { uid, bmForFull } ) ) ;
104
102
port . postMessage ( { ctype : ctype , cdata : bmForFull } ) ;
105
103
break ;
@@ -109,6 +107,7 @@ chrome.runtime.onConnect.addListener(function(port) {
109
107
return ;
110
108
}
111
109
const bmForMini = BookmarkLib . getBookmark ( ) ;
110
+ sendPageview ( '/mini_mode_notification' ) ;
112
111
sendEvent ( currentVersion , 'getbookmark_from_mini' , 'get_bookmark_' + uid , JSON . stringify ( { uid, bmForMini } ) ) ;
113
112
port . postMessage ( {
114
113
ctype,
@@ -146,6 +145,7 @@ chrome.runtime.onConnect.addListener(function(port) {
146
145
break ;
147
146
case 'getbookmark_menu' :
148
147
BookmarkLib . getBookmarkMenu ( menu => {
148
+ sendPageview ( '/bookmark_manager_page' ) ;
149
149
sendEvent ( currentVersion , 'getbookmark_menu' , 'getbookmark_menu_' + uid , JSON . stringify ( { uid } ) ) ;
150
150
port . postMessage ( { ctype, cdata : menu } ) ;
151
151
} ) ;
@@ -180,6 +180,7 @@ chrome.runtime.onConnect.addListener(function(port) {
180
180
} ) ;
181
181
break ;
182
182
case 'get_config' :
183
+ sendPageview ( '/popup' ) ;
183
184
sendEvent ( currentVersion , 'get_config' , 'get_config_' + uid , JSON . stringify ( { uid, config : store . getters . config } ) ) ;
184
185
port . postMessage ( { ctype, cdata : store . getters . config } ) ;
185
186
break ;
@@ -191,6 +192,7 @@ chrome.runtime.onConnect.addListener(function(port) {
191
192
random : cdata . random ,
192
193
frequency : cdata . frequency ,
193
194
currentNotifyLocation : cdata . currentNotifyLocation ,
195
+ ga : cdata . ga ,
194
196
} ) ;
195
197
port . postMessage ( { ctype, cdata : true } ) ;
196
198
break ;
@@ -203,6 +205,7 @@ chrome.runtime.onConnect.addListener(function(port) {
203
205
} ) ;
204
206
break ;
205
207
case 'get_block_list' :
208
+ sendPageview ( '/block_list_page' ) ;
206
209
sendEvent ( currentVersion , 'get_block_list' , 'get_block_list_' + uid , JSON . stringify ( { uid } ) ) ;
207
210
BookmarkLib . getBlockList ( blockedBookmarks => {
208
211
port . postMessage ( { ctype, cdata : blockedBookmarks } ) ;
@@ -245,6 +248,9 @@ chrome.bookmarks.onRemoved.addListener((id, removeInfo) => {
245
248
chrome . runtime . onInstalled . addListener ( detail => {
246
249
if ( detail . reason == 'update' ) {
247
250
sendEvent ( currentVersion , 'update_extension' , uid , '' ) ;
251
+ // 弹出推广页面
252
+ window . open ( 'https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324' ) ;
253
+ return ;
248
254
chrome . notifications . create (
249
255
{
250
256
type : 'basic' ,
@@ -254,8 +260,6 @@ chrome.runtime.onInstalled.addListener(detail => {
254
260
} ,
255
261
function ( notification_id ) { }
256
262
) ;
257
- // 弹出推广页面
258
- window . open ( 'https://creatorsdaily.com/9999e88d-0b00-46dc-8ff1-e1d311695324' ) ;
259
263
}
260
264
if ( detail . reason === 'install' ) {
261
265
sendEvent ( currentVersion , 'install_extension' , uid , '' ) ;
0 commit comments