The HogFunction resource allows you to create and manage custom Hog functions for transforming events, routing data, and executing custom logic in PostHog.
Example Usage#
Basic Transformation Function#
Function with Filters#
Destination Function#
Function with Inputs#
Function with Execution Order#
Resource Properties#
Optional Arguments (all optional)#
name(string): Name of the Hog functiondescription(string): Description of the Hog functionenabled(boolean): Whether the Hog function is enabled (default: true)hog(string): The Hog code to execute (not required when using a template)type(string): Type of Hog function -"destination","siteDestination","internalDestination","sourceWebhook","siteApp", or"transformation"filtersJson(string): JSON string defining filters for when the Hog function should executeinputsJson(string): JSON string containing the input values for the Hog functionmappingsJson(string): JSON array of mapping configurationsmaskingJson(string): JSON object configuring PII maskingtemplateId(string): ID of a template to use as the basis for this Hog functionexecutionOrder(number): Order in which this Hog function executes (0-32767)iconUrl(string): URL of the icon for this Hog function
Attributes#
- All configured properties
Function Types#
Transformation#
Transform events before they're stored:
Destination#
Send events to external systems:
Site Destination#
Browser-side destinations:
Site App#
Browser-side applications:
Hog Language Basics#
Event Transformation#
Conditional Logic#
Using Inputs#
Best Practices#
1. Use Descriptive Names#
2. Filter Appropriately#
Only process events that need transformation:
3. Set Execution Order#
Control the order of transformations:
Common Use Cases#
Add Timestamp#
User Classification#
Webhook Integration#
Data Sanitization#
Troubleshooting#
Function Not Executing#
Issue: Hog function doesn't run
Solution:
- Verify
enabledis true - Check
filtersJsonmatches your events - Ensure
executionOrderdoesn't conflict - Review Hog syntax for errors
Syntax Errors#
Issue: Hog code has syntax errors
Solution:
- Test Hog code in PostHog's Hog debugger
- Check for missing brackets, quotes, or semicolons
- Verify function signature matches type (e.g.,
transform(event))
Performance Issues#
Issue: Functions slow down event processing
Solution:
- Use filters to process only necessary events
- Avoid expensive operations in hot paths
- Consider using
executionOrderto optimize