@@ -21,10 +21,12 @@ class Analytics {
21
21
*
22
22
* @param {String } writeKey
23
23
* @param {Object } [options] (optional)
24
- * @property {Number } flushAt (default: 20)
25
- * @property {Number } flushInterval (default: 10000)
26
- * @property {String } host (default: 'https://api.segment.io')
27
- * @property {Boolean } enable (default: true)
24
+ * @property {Number } [flushAt] (default: 20)
25
+ * @property {Number } [flushInterval] (default: 10000)
26
+ * @property {String } [host] (default: 'https://api.segment.io')
27
+ * @property {Boolean } [enable] (default: true)
28
+ * @property {Object } [axiosConfig] (optional)
29
+ * @property {Object } [axiosInstance] (default: axios.create(options.axiosConfig))
28
30
*/
29
31
30
32
constructor ( writeKey , options ) {
@@ -35,6 +37,12 @@ class Analytics {
35
37
this . queue = [ ]
36
38
this . writeKey = writeKey
37
39
this . host = removeSlash ( options . host || 'https://api.segment.io' )
40
+ this . path = removeSlash ( options . path || '/v1/batch' )
41
+ let axiosInstance = options . axiosInstance
42
+ if ( axiosInstance == null ) {
43
+ axiosInstance = axios . create ( options . axiosConfig )
44
+ }
45
+ this . axiosInstance = axiosInstance
38
46
this . timeout = options . timeout || false
39
47
this . flushAt = Math . max ( options . flushAt , 1 ) || 20
40
48
this . flushInterval = options . flushInterval || 10000
@@ -125,7 +133,7 @@ class Analytics {
125
133
* Send a screen `message`.
126
134
*
127
135
* @param {Object } message
128
- * @param {Function } fn (optional)
136
+ * @param {Function } [callback] (optional)
129
137
* @return {Analytics }
130
138
*/
131
139
@@ -256,7 +264,7 @@ class Analytics {
256
264
callback ( err , data )
257
265
}
258
266
259
- // Don't set the user agent if we're not on a browser. The latest spec allows
267
+ // Don't set the user agent if we're on a browser. The latest spec allows
260
268
// the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
261
269
// and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
262
270
// but browsers such as Chrome and Safari have not caught up.
@@ -267,7 +275,7 @@ class Analytics {
267
275
268
276
const req = {
269
277
method : 'POST' ,
270
- url : `${ this . host } /v1/batch ` ,
278
+ url : `${ this . host } ${ this . path } ` ,
271
279
auth : {
272
280
username : this . writeKey
273
281
} ,
0 commit comments