Skip to main content

Hog Function

Create and manage custom Hog functions for data transformation
2 min read

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 function
  • description (string): Description of the Hog function
  • enabled (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 execute
  • inputsJson (string): JSON string containing the input values for the Hog function
  • mappingsJson (string): JSON array of mapping configurations
  • maskingJson (string): JSON object configuring PII masking
  • templateId (string): ID of a template to use as the basis for this Hog function
  • executionOrder (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 enabled is true
  • Check filtersJson matches your events
  • Ensure executionOrder doesn'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 executionOrder to optimize

Additional Resources#