Targeted Campaigns: Country-Based Filtering

The devlog-ist/landing project focuses on creating effective landing pages and user onboarding flows. A recent feature addition enables country-specific targeting for email campaigns, leveraging country detection during user onboarding to improve campaign relevance.

The Problem

Previously, email campaigns were broadcast to all users, regardless of their location. This lack of targeting resulted in lower engagement rates and potentially irrelevant content being delivered to users in different regions.

The Solution

To address this, a country-based filtering system was implemented. This involves:

  1. Adding a country_code field to users: This field stores the ISO 3166-1 alpha-2 country code for each user.
  2. Adding a country_filter field to campaigns: This allows campaign creators to specify which countries the campaign should target.
  3. Auto-detecting country from CVs: During user onboarding, the system now automatically extracts the user's country from their uploaded CV using Prism AI.

Implementation Details

The implementation includes a backfill command to populate the country_code for existing users. The backfill command ensures that all existing users have their country information updated, enabling targeted campaigns for the entire user base. The admin interface, likely built with Filament, was also updated to allow for easy management of country options when creating or editing campaigns.

Here's an example of how you might filter campaigns in PHP based on a user's country:

<?php

function get_targeted_campaigns(string $userCountryCode, array $campaigns):
array
{
    $targetedCampaigns = array_filter($campaigns, function ($campaign) use ($userCountryCode) {
        if (empty($campaign['country_filter'])) {
            return true; // If no country filter, campaign applies to everyone
        }

        return in_array($userCountryCode, $campaign['country_filter']);
    });

    return array_values($targetedCampaigns);
}

// Example Usage:
$userCountry = 'US';
$allCampaigns = [
    ['name' => 'Global Campaign', 'country_filter' => []],
    ['name' => 'US Campaign', 'country_filter' => ['US']],
    ['name' => 'UK Campaign', 'country_filter' => ['GB']],
];

$relevantCampaigns = get_targeted_campaigns($userCountry, $allCampaigns);

print_r($relevantCampaigns);

?>

This PHP code demonstrates how to filter campaigns based on the user's country code. The get_targeted_campaigns function iterates through the available campaigns and checks if the user's country code is present in the campaign's country_filter. If the filter is empty, the campaign is considered global and included for all users.

The Takeaway

By implementing country-based campaign filtering, the devlog-ist/landing project can now deliver more relevant content to its users, leading to increased engagement and improved campaign performance. Consider adding geo-targeting to your own projects to improve relevance and engagement. Start by identifying key user attributes and tailoring content to match.

Targeted Campaigns: Country-Based Filtering
GERARDO RUIZ

GERARDO RUIZ

Author

Share: