@@ -21,10 +21,12 @@ class Analytics {
2121 *
2222 * @param {String } writeKey
2323 * @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))
2830 */
2931
3032 constructor ( writeKey , options ) {
@@ -35,6 +37,12 @@ class Analytics {
3537 this . queue = [ ]
3638 this . writeKey = writeKey
3739 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
3846 this . timeout = options . timeout || false
3947 this . flushAt = Math . max ( options . flushAt , 1 ) || 20
4048 this . flushInterval = options . flushInterval || 10000
@@ -125,7 +133,7 @@ class Analytics {
125133 * Send a screen `message`.
126134 *
127135 * @param {Object } message
128- * @param {Function } fn (optional)
136+ * @param {Function } [callback] (optional)
129137 * @return {Analytics }
130138 */
131139
@@ -256,7 +264,7 @@ class Analytics {
256264 callback ( err , data )
257265 }
258266
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
260268 // the User-Agent header (see https://fetch.spec.whatwg.org/#terminology-headers
261269 // and https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader),
262270 // but browsers such as Chrome and Safari have not caught up.
@@ -267,7 +275,7 @@ class Analytics {
267275
268276 const req = {
269277 method : 'POST' ,
270- url : `${ this . host } /v1/batch ` ,
278+ url : `${ this . host } ${ this . path } ` ,
271279 auth : {
272280 username : this . writeKey
273281 } ,
0 commit comments