feat: Add an analytics module and local and posthog providers (#12505)
* feat: Add an analytics module and local and posthog providers * fix: Add tests and wire up in missing places * fix: Address feedback and add missing module typing * fix: Address feedback and add missing module typing --------- Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
49 files changed
+1009
No files matched your search
@@ -0,0 +1,8 @@
|
||||
import { ModuleProvider, Modules } from "@medusajs/framework/utils"
|
||||
import { LocalAnalyticsService } from "./services/local-analytics"
|
||||
|
||||
const services = [LocalAnalyticsService]
|
||||
|
||||
export default ModuleProvider(Modules.ANALYTICS, {
|
||||
services,
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
LocalAnalyticsServiceOptions,
|
||||
Logger,
|
||||
ProviderIdentifyAnalyticsEventDTO,
|
||||
ProviderTrackAnalyticsEventDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import { AbstractAnalyticsProviderService } from "@medusajs/framework/utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
export class LocalAnalyticsService extends AbstractAnalyticsProviderService {
|
||||
static identifier = "analytics-local"
|
||||
protected config_: LocalAnalyticsServiceOptions
|
||||
protected logger_: Logger
|
||||
|
||||
constructor(
|
||||
{ logger }: InjectedDependencies,
|
||||
options: LocalAnalyticsServiceOptions
|
||||
) {
|
||||
super()
|
||||
this.config_ = options
|
||||
this.logger_ = logger
|
||||
}
|
||||
|
||||
async track(data: ProviderTrackAnalyticsEventDTO): Promise<void> {
|
||||
this.logger_.debug(
|
||||
`Tracking event: '${data.event}', actor_id: '${
|
||||
data.actor_id ?? "-"
|
||||
}', group: '${data.group?.id ?? "-"}', properties: '${JSON.stringify(
|
||||
data.properties
|
||||
)}'`
|
||||
)
|
||||
}
|
||||
|
||||
async identify(data: ProviderIdentifyAnalyticsEventDTO): Promise<void> {
|
||||
this.logger_.debug(
|
||||
`Identifying user: '${data.actor_id ?? "-"}', group: '${
|
||||
"group" in data ? data.group.id : "-"
|
||||
}', properties: '${JSON.stringify(data.properties)}'`
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user