Creating New Functions

Getting Started

  1. Use the following repo as a template for building your own Freshpaint Functions. https://github.com/freshpaint-io/functions-template.

  2. Create a new repository from this template, implement the methods in index.js, and configure your function settings in config.json. Additional configuration options are provided below.

  3. Navigate to the Functions page in Freshpaint, and provide the URL of your new repository to add your function to the Freshpaint UI:

If you attempt to create a new function that uses a private GitHub repo, a request to set up GitHub OAuth and install the Freshpaint GitHub app will appear. Follow the provided steps to allow your function to be added:

4. With your function now added, navigate to Functions under Destinations, to complete the configuration:

5. Complete the configuration by adding your credentials:

Your function is now configured and available as a destination. To send data to this Function, enable it in the same way that existing destinations are enabled on the events page.

Note on Backfills: There is no need for any additional backfill-specific configuration. You can rerun all events through the same functions code, as long as the endpoints you're already using can handle the added volume.

Function configuration

You can provide an optional configuration file config.json in your function's GitHub repository. The file should include a JSON object with the following fields:

Config Fields

Types of config fields

There are several different types you can use for your config field

  • string

  • boolean

  • number

  • list - A list of strings

  • select - A dropdown menu

  • radio - A set of radio buttons

Writing your function

Each handler (onTrack, onIdentify, onGroup, and onPage) accepts two parameters:

Event Format

The format of the event argument passed to your event handlers differs slightly depending on which handler (onTrack, onIdentify, onGroup, and onPage) is being invoked. Details about the shape of the object can be found below:

Base properties present on all event objects

The following base properties are available on every event object regardless of the handler.

Additional properties: onGroup

Additional properties: onIdentify

Additional properties: onPage

Additional properties: onTrack

Last updated