DEV Community

Gerardo Andrés Ruiz Castillo
Gerardo Andrés Ruiz Castillo

Posted on • Originally published at geanruca.gitvlg.com

Tracking User Acquisition with UTM Parameters

Introduction

Understanding where your users come from is crucial for optimizing marketing efforts and improving user acquisition. This post explores how to track UTM parameters, HTTP Referer, and landing page information upon user registration, providing valuable insights into your acquisition channels.

Capturing Acquisition Data

When a new user signs up, capturing information about their origin can help determine which marketing campaigns are most effective. Key data points to track include:

  • UTM Parameters: utm_source, utm_medium, and utm_campaign are standard URL parameters used to track the source, medium, and specific campaign that drove the user to your site.
  • HTTP Referer: The HTTP Referer header indicates the previous webpage the user was on before arriving at your registration page. This can reveal valuable information about referring websites.
  • Landing Page: The specific landing page on your site where the user initiated the registration process. This helps identify which pages are most effective at driving sign-ups.

Implementation Pattern

A common pattern for capturing this data involves using a combination of session storage and cookies. Here's a general outline of the process:

  1. On Landing: When a user lands on your site, check for UTM parameters in the URL. If present, store them in a session.
  2. Capture Referrer: Record the HTTP Referer header.
  3. Set Cookies: If UTM parameters or a referrer are present, store them in cookies to persist the data across multiple pages.
  4. On Registration: When the user submits the registration form, retrieve the UTM parameters, referrer, and landing page from the session or cookies.
  5. Store with User Data: Save the captured acquisition data along with the new user's information in your database.

Data Storage

When storing the acquisition data, consider adding the following fields to your users table or a related table:

  • utm_source
  • utm_medium
  • utm_campaign
  • referrer
  • landing_page

These fields will allow you to easily analyze the effectiveness of different acquisition channels.

Example

Here's an example of how you might capture this data in a simplified registration form:

<?php
// Retrieve UTM parameters from the URL
$utm_source = $_GET['utm_source'] ?? null;
$utm_medium = $_GET['utm_medium'] ?? null;
$utm_campaign = $_GET['utm_campaign'] ?? null;

// Retrieve the HTTP Referer
$referrer = $_SERVER['HTTP_REFERER'] ?? null;

// Get the landing page
$landing_page = $_SERVER['REQUEST_URI'];

// Store the data in the database
$user = new User();
$user->utm_source = $utm_source;
$user->utm_medium = $utm_medium;
$user->utm_campaign = $utm_campaign;
$user->referrer = $referrer;
$user->landing_page = $landing_page;
$user->save();
?>
Enter fullscreen mode Exit fullscreen mode

Conclusion

Tracking UTM parameters, HTTP Referer, and landing page information provides valuable insights into your user acquisition efforts. By implementing a system to capture and store this data, you can gain a better understanding of which channels are most effective and optimize your marketing campaigns accordingly. Take the time to implement this tracking in your registration process to unlock valuable data about your users' origins.

Top comments (0)