What is a hook?
A hook is a mechanism that enables apps to receive data updates in real time, and that connects two different applications. The Countly Hooks plugin will bring together triggers and effects. It is incredibly helpful when you're working with data updates that need to be notified immediately such as payment transactions and purchasing process. The Hooks plugin allows you to capture events and user data from Countly, or post data to Countly via generated API endpoint. When an event is captured on the Hook, it serializes data about that event and you can choose to send this data by HTTP request or email. It allows creating rules, where each rule would have one trigger, and one or many effects.
The Hooks plugin is available in Enterprise Edition.
Hooks plugin allows you to listen to triggers on incoming data and internal events on Countly, which will then send relevant data to external URL in real-time or send email. In other words, Hooks let you transfer data to other services you used when events happen in your Countly account.
You can trigger a Hook via :
- Incoming Data
- Internal Event
- API endpoint
Creating a new Hook
You can access the Hooks plugin in the Utilities section. Please click the green “+ New Hook” button on the right-top of the page.
Give the Hook a name. Please keep it simple, understandable, and short. You may use Hook Description field to explain to your colleagues why you created this hook. Avoid using special characters or long descriptions.
Select an application for the hook. You can select only one application for each Hook.
There are 3 options to trigger this Hook:
- Incoming Data: It listens to events defined for the selected application and checks for matching data, and triggers an effect if matching data is found. You can apply a filter to events like filtering by event or user properties.
- Internal Event: Countly has many internal events, like entering or exiting cohorts. You can specify which cohort to listen to, or which system logs action, etc. In addition to that, you can track user profile changes, namely user profile creations, updates, and deletions.
These internal events could be like:
It is important to note that /userprofile/update will also get triggered when a new user created will output updated user properties. The old user profile can also be added in order to allow Hook consumers to do a comparison.
- API endpoint: It generates a random ID to use in API endpoint and you can use this URL in some external services, like webhook, by copying it.
After defining the trigger, the next step is to select the Action. You can select one of these two options:
- Send an email: This action enables you to send an internal email with data from the trigger, which can be formatted as a nested list for displaying JSON objects.
- Make HTTP Request: You can simply provide a URL to call and pass the data from the trigger. It allows you to select either call via GET or POST.
Action: POST data: this makes a POST request to a URL.
Action: GET data: this makes a GET request to a URL with query data.
It is possible to add more than one action for a selected trigger on a Hook. Use the “+ Add action” button to add a new action.
After filling and selecting the mandatory fields, click the “Create hook” button.
You can use the Hooks table to get an overview of created Hooks. If you want to disable any Hook, please use the toggle on the Status column. Also, you can edit or delete your hooks by clicking the 3-dot overflow menu on the right side of the Hook rows, and by clicking edit or delete buttons.