Publishing Custom Analytics Events Data


Instead of publishing already available analytics events data, it is also possible to publish custom analytics data with the existing event schema. This guide will explain the steps required to do it.


  • Note that, support for publishing custom analytics events data has been introduced to WSO2 API Manager 4.1.0 via an U2 update (Update level 21).
  • You can check if this feature is available in your current pack by viewing the trace logs without adding the jar containing the implemented class as here.
  • If the feature is available in the pack you will be able to see a property object named property which includes apiContext and userName as default values.
    "userName":"[email protected]"

This section will cover the steps required to create a sample and configure the created sample with WSO2 API-M.

Creating the Sample

You have to create a new Java/Maven project.

There is an already created sample and if you wish to use that sample instead of developing the sample from scratch, then you can ignore the steps of creating the sample and start from here.

This section will cover how to configure the pom.xml, class implementations and building the created sample.

Configuring pom.xml

Add wso2-nexus repository to pom.xml.

    <name>WSO2 internal Repository</name>

Add dependencies,



  • The versions for ${carbon.apimgt.version}, and ${synapse.version} can be found in the jar versions available in the current API Manager 4.1.0 package.
  • Since this feature support available in the latest update levels, you have to follow the below steps to add the required artifacts to the local m2 repository and point it as a repository in pom file.
    1. Find the org.wso2.carbon.apimgt.gateway and jars inside the <APIM_HOME>/repository/components/plugins directory in latest U2 updated APIM pack.
    2. Add the above jars to the local m2 manually.
      mvn install:install-file -Dfile=<PATH_TO_FILE>/org.wso2.carbon.apimgt.gateway_<COMPENENT_VERSION>.jar -DgroupId=org.wso2.carbon.apimgt -DartifactId=org.wso2.carbon.apimgt.gateway -Dversion=<COMPENENT_VERSION> -Dpackaging=jar
      mvn install:install-file -Dfile=<PATH_TO_FILE>/org.wso2.carbon.apimgt.common.analytics_<COMPENENT_VERSION>.jar -DgroupId=org.wso2.carbon.apimgt -Dversion=<COMPENENT_VERSION> -Dpackaging=jar
    3. Point local m2 repository in project pom
          <id> local-maven-repo </id>
          <url> file://home/user/.m2/repository </url>
      Follow the same URL pattern when providing the repo url

Implementing Required Class

AnalyticsCustomDataProvider Implementation Class

Custom analytics data can be added to the existing event schema with the use of a class of type AnalyticsCustomDataProvider. Therefore, it is required to implement a class from the AnalyticsCustomDataProvider interface. By overriding the getCustomProperties method it is possible to push custom analytics data.

In order to achieve this behavior, create a class implementing the AnalyticsCustomDataProvider Interface of

Implementation of this class should look something similar to this.

Build the Project

Build the project using,

mvn clean install

Configuring the Sample

This section will cover the steps required to configure WSO2 API-M Gateway for the sample created above. The steps covered are adding the .jar file, configuring the deployment.toml file, and enabling the logs.

  1. Add the jar file created in the target directory after building the project.

    Place the created .jar file inside the wso2am-4.1.0/repository/components/lib directory.

  2. Configure the deployment.toml file.

    Edit the configurations in the deployment.toml file located inside wso2am-4.1.0/repository/conf with the following configuration.

    enable = true
    properties."" = "<FullyQualifiedClassNameOfAnalyticsCustomDataProviderImplClass>"
    type = "elk"

    This configuration will be used when engaging the custom data provider class.


    Type should be given as elk as this property value is filtered out in cloud implementation.

  3. Enable Logs

    To enable trace logs for the component:, edit the file located inside wso2am-4.1.0/repository/conf directory.

    1. Add new publisher to the loggers list:
      loggers = org-wso2-analytics-publisher, ...(list of other available loggers)
    2. Add the following configurations after the loggers: = = TRACE = CARBON_TRACE_LOGFILE
  4. Now you can trigger an event and check the <WSO2AM-4.1.0-HOME>/repository/logs/wso2carbon-trace-messages.log to find the event object passed out from API Manager.

TRACE {} - [{ Cloud-Analytics-Queue-Worker-pool-2-thread-1 }] - 
 Adding event: 
         "userName":"[email protected]"