Create a custom plugin
You can create your custom pluggable for Analytics. This may be helpful if you want to integrate your app with a custom analytics backend.
To create a plugin implement the AnalyticsProvider
interface:
1import { Analytics, AnalyticsProvider } from 'aws-amplify';2
3export default class MyAnalyticsProvider implements AnalyticsProvider {4 // category and provider name5 static category = 'Analytics';6 static providerName = 'MyAnalytics';7
8 // you need to implement these four methods9 // configure your provider10 configure(config: object): object;11
12 // record events and returns true if succeeds13 record(params: object): Promise<boolean>;14
15 // return 'Analytics';16 getCategory(): string;17
18 // return the name of you provider19 getProviderName(): string;20}
You can now register your pluggable:
1// add the plugin2Analytics.addPluggable(new MyAnalyticsProvider());3
4// get the plugin5Analytics.getPluggable(MyAnalyticsProvider.providerName);6
7// remove the plugin8Analytics.removePluggable(MyAnalyticsProvider.providerName);9
10// send configuration into Amplify11Analytics.configure({12 MyAnalyticsProvider: {13 // My Analytics provider configuration14 }15});
The default provider (Amazon Pinpoint) is in use when you call Analytics.record()
unless you specify a different provider: Analytics.record({..},'MyAnalytics')
.