smartanalytics/ts/smartanalytics.classes.analytics.ts

40 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2017-08-23 12:55:11 +00:00
import * as plugins from './smartanalytics.plugins'
export class Analytics {
2017-08-23 23:06:09 +00:00
projectId: string
2017-08-23 12:55:11 +00:00
appName: string
apiEndPoint: string
secretKey: string = ''
constructor (optionsArg: {
2017-08-23 23:06:09 +00:00
projectIdArg: string
2017-08-23 12:55:11 +00:00
appNameArg: string
apiEndPointArg: string
secretKeyArg?: string
}) {
2017-08-23 23:06:09 +00:00
this.projectId = optionsArg.projectIdArg
2017-08-23 12:55:11 +00:00
this.appName = optionsArg.appNameArg
this.apiEndPoint = optionsArg.apiEndPointArg
if (optionsArg.secretKeyArg) {
this.secretKey = optionsArg.secretKeyArg
}
}
2017-08-25 10:38:49 +00:00
async recordEvent (eventIdentifierArg: string, analyticsDataArg: any) {
2017-08-23 12:55:11 +00:00
let dataToSend = {
2017-08-23 23:06:09 +00:00
projectId: this.projectId,
2017-08-23 12:55:11 +00:00
appName: this.appName,
2017-08-25 10:38:49 +00:00
eventIdentifier: eventIdentifierArg,
2017-08-23 12:55:11 +00:00
analyticsData: analyticsDataArg
}
await plugins.smartrequest.post(this.apiEndPoint, {
headers: {
2017-08-23 15:33:30 +00:00
'authenticate': this.secretKey,
'Content-Type': 'application/json'
2017-08-23 12:55:11 +00:00
},
2017-08-23 15:33:30 +00:00
requestBody: dataToSend
}).catch(err => {
console.log(err)
2017-08-23 12:55:11 +00:00
})
}
}