Page updated Nov 9, 2023

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 name
5 static category = 'Analytics';
6 static providerName = 'MyAnalytics';
7
8 // you need to implement these four methods
9 // configure your provider
10 configure(config: object): object;
11
12 // record events and returns true if succeeds
13 record(params: object): Promise<boolean>;
14
15 // return 'Analytics';
16 getCategory(): string;
17
18 // return the name of you provider
19 getProviderName(): string;
20}

You can now register your pluggable:

1// add the plugin
2Analytics.addPluggable(new MyAnalyticsProvider());
3
4// get the plugin
5Analytics.getPluggable(MyAnalyticsProvider.providerName);
6
7// remove the plugin
8Analytics.removePluggable(MyAnalyticsProvider.providerName);
9
10// send configuration into Amplify
11Analytics.configure({
12 MyAnalyticsProvider: {
13 // My Analytics provider configuration
14 }
15});

The default provider (Amazon Pinpoint) is in use when you call Analytics.record() unless you specify a different provider: Analytics.record({..},'MyAnalytics').