Create a custom plugin
These docs cover Amplify Gen 1. For new web apps, we recommend the latest AWS Amplify, with a simplified CLI and native integrations for databases, storage, and AI models. Get started with the latest AWS Amplify.
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:
import { Analytics, AnalyticsProvider } from 'aws-amplify';
export default class MyAnalyticsProvider implements AnalyticsProvider { // category and provider name static category = 'Analytics'; static providerName = 'MyAnalytics';
// you need to implement these four methods // configure your provider configure(config: object): object;
// record events and returns true if succeeds record(params: object): Promise<boolean>;
// return 'Analytics'; getCategory(): string;
// return the name of you provider getProviderName(): string;}You can now register your pluggable:
// add the pluginAnalytics.addPluggable(new MyAnalyticsProvider());
// get the pluginAnalytics.getPluggable(MyAnalyticsProvider.providerName);
// remove the pluginAnalytics.removePluggable(MyAnalyticsProvider.providerName);
// send configuration into AmplifyAnalytics.configure({ MyAnalyticsProvider: { // My Analytics provider configuration }});The default provider (Amazon Pinpoint) is in use when you call Analytics.record() unless you specify a different provider: Analytics.record({..},'MyAnalytics').