UTM parameters are a set 5 five parameters that allow you to track the effectiveness of marketing campaigns across traffic sources. These parameters were first introduced by Google Analytics, but are now a common way to identify where traffic to your website is coming from. They are especially useful when running ad campaigns, as nearly every platform will set them when sending traffic to your website.
The parameters are attached to a link using query parameters, for example:
https://www.example.com/page?utm_source=twitter&utm_medium=social&utm_campaign=twitter-campaign
Capturing UTM parameters
PostHog is set up to automatically capture any UTM parameters that are present when a user visits your website. These parameters will then be set as properties on any event that you send to PostHog.
PostHog supports all 5 parameters:
Parameter | Purpose | Example |
---|---|---|
utm_source | Identifies which site sent the traffic, for example, traffic from Google or Facebook. | utm_source=google |
utm_medium | Allows you to track the type of link was used, for example cost per click, or social sharing. | utm_medium=cpc |
utm_campaign | Helps identify specific promotions or campaigns, for example, when you run an ad campaign. | utm_campaign=google-ad-campaign. |
utm_content | Can be used to differentiate the same link on different places. | utm_content=footer-link |
utm_term | Used to identify paid keyword searches. | utm_term=analytics+open+source |
Here's an example of what an event looks like when all 5 UTM parameters are set.
Note: Along with being set on events, these UTM properties will also be added to the profile of the user who sent the event.
Custom UTM parameters
You can configure posthog-js to capture any custom query parameters that you want to track by adding them to the custom_utm_params
array.
posthog.init('<ph_project_api_key>', {custom_campaign_params: ["my_custom_utm_source"]})// Will automatically capture `example.com?my_custom_utm_source=twitter`
Filtering based on UTM parameters
One of the most common uses for UTM parameters is to filter down page views to only a single source or campaign. This allows you to then create insights that track and compare the effectiveness of different ad providers or using different content.
As an example, let's say we want to use UTM parameters to track the conversion rate of traffic from a particular campaign. In order to do this, we'll create a funnel insight with the following filter applied.
Note: You can only filter by UTM properties once they have been set on at least one event. If you don't see them as an option, it probably means that you haven't yet received an event where that parameter was set.
This filter means that we only want to see events where the utm_campaign
was set to spring sale
.
Next, we can get a better idea of which platforms are giving us the best result by breaking down based on the UTM Source.
This will allow us to see how our conversion rate compares across platforms where we're running our ad campaign, and figure out where we're getting the highest-quality traffic from.