1
1
import path from "path"
2
- import Configstore from "configstore"
3
- import createFetch from "@turist/fetch"
4
2
import { Store } from "./store"
5
3
import { ensureDirSync } from "fs-extra"
6
- import { isTruthy } from "gatsby-core-utils"
7
- import { InMemoryConfigStore } from "./in-memory-store"
8
4
9
- const fetch = createFetch ( )
5
+ import { InMemoryConfigStore } from "./in-memory-store"
10
6
11
7
/* The events data collection is a spooled process that
12
8
* buffers events to a local fs based buffer
@@ -15,20 +11,15 @@ const fetch = createFetch()
15
11
* to continue even when working offline.
16
12
*/
17
13
export class EventStorage {
18
- analyticsApi =
19
- process . env . GATSBY_TELEMETRY_API || `https://analytics.gatsbyjs.com/events`
20
- config : Configstore | InMemoryConfigStore
14
+ analyticsApi = process . env . GATSBY_TELEMETRY_API
15
+ config : InMemoryConfigStore
21
16
store : Store
22
17
verbose : boolean
23
18
debugEvents : boolean
24
19
disabled : boolean
25
20
26
21
constructor ( ) {
27
- try {
28
- this . config = new Configstore ( `gatsby` , { } , { globalConfigPath : true } )
29
- } catch ( e ) {
30
- this . config = new InMemoryConfigStore ( )
31
- }
22
+ this . config = new InMemoryConfigStore ( )
32
23
33
24
const baseDir = path . dirname ( this . config . path )
34
25
@@ -39,59 +30,23 @@ export class EventStorage {
39
30
}
40
31
41
32
this . store = new Store ( baseDir )
42
- this . verbose = isTruthy ( process . env . GATSBY_TELEMETRY_VERBOSE )
43
- this . debugEvents = isTruthy ( process . env . GATSBY_TELEMETRY_DEBUG )
44
- this . disabled = isTruthy ( process . env . GATSBY_TELEMETRY_DISABLED )
33
+ this . verbose = false
34
+ this . debugEvents = false
35
+ this . disabled = true
45
36
}
46
37
47
38
isTrackingDisabled ( ) : boolean {
48
39
return this . disabled
49
40
}
50
41
51
- addEvent ( event : unknown ) : void {
52
- if ( this . disabled ) {
53
- return
54
- }
55
-
56
- const eventString = JSON . stringify ( event )
57
-
58
- if ( this . debugEvents || this . verbose ) {
59
- console . log ( `Captured event:` , JSON . parse ( eventString ) )
60
-
61
- if ( this . debugEvents ) {
62
- // Bail because we don't want to send debug events
63
- return
64
- }
65
- }
66
-
67
- this . store . appendToBuffer ( eventString + `\n` )
68
- }
42
+ addEvent ( event : unknown ) : void { }
69
43
70
44
async sendEvents ( ) : Promise < boolean > {
71
- return this . store . startFlushEvents ( async ( eventsData : string ) => {
72
- const events = eventsData
73
- . split ( `\n` )
74
- . filter ( e => e && e . length > 2 ) // drop empty lines
75
- . map ( e => JSON . parse ( e ) )
76
-
77
- return this . submitEvents ( events )
78
- } )
45
+ return true
79
46
}
80
47
81
48
async submitEvents ( events : unknown ) : Promise < boolean > {
82
- try {
83
- const res = await fetch ( this . analyticsApi , {
84
- method : `POST` ,
85
- headers : {
86
- "content-type" : `application/json` ,
87
- "user-agent" : this . getUserAgent ( ) ,
88
- } ,
89
- body : JSON . stringify ( events ) ,
90
- } )
91
- return res . ok
92
- } catch ( e ) {
93
- return false
94
- }
49
+ return true
95
50
}
96
51
97
52
getUserAgent ( ) : string {
0 commit comments