Integrating Segment with Usermaven

Segment

Usermaven effortlessly connects with Segment, a Customer Data Platform (CDP), allowing you to track event data and send it to different destinations. This dynamic pairing not only simplifies event tracking but also opens avenues for strategic data utilization. Setting up Usermaven with Segment is a breeze, requiring just a few clicks for seamless integration.

How the Usermaven Integration Works with Segment

How Segment works is that you seamlessly integrate it into your application to commence data collection. This integration extends across various platforms, allowing you to add Segment to your website, mobile apps, servers, or cloud applications. When a customer/user engages with any of your sources, e.g., your website, Segment captures the data and directs it to a specified destination. Destinations are tools for things like ads, email marketing, and analytics. Usermaven is one such analytics tool. Segment servers retain an archived copy of the data and send it to the destination i.e. Usermaven.

This seamless data flow ensures not only real-time insights but also empowers your long-term analytics strategy by providing a consolidated repository of historical user interactions.

This is how it works:

  1. Access the Segment web app and navigate to the "Catalog" section.

  2. Within the Catalog, select "Destinations."

  3. Utilize the search function to locate "Usermaven" in the Destinations Catalog, and choose the Usermaven destination.

  4. Click on "Configure Usermaven" to initiate the configuration process.

  5. Choose an existing Source from your Segment account to establish a connection with Usermaven, specifically under the "Actions" category.

  6. Open the Usermaven App and proceed to "Workspace Settings" > "General Settings."

  7. Copy the API Key provided in the Usermaven workspace settings.

  8. Return to the Segment web app and navigate to the settings for the "Usermaven (Actions)" destination.

  9. Paste the copied API Key into the designated field within the "Usermaven (Actions)" destination settings in Segment.

By following these steps, you'll seamlessly configure the Usermaven destination in Segment, ensuring a smooth integration process.

Server Side Tracking with Segment for Usermaven

Seamless Server-Side Tracking with Segment involves crucial steps to effectively piece together user activities. Here’s what you need to know:

  • Anonymous ID Variability : When handling events through server-side tracking such as the Segment PHP SDK, it's imperative to note that the anonymous ID can exhibit variability. This variance may lead to discrepancies in stitching together the user timeline accurately.

  • IP Address Transmission : The transmission of IP addresses in server-side tracking utilizes the server's IP address. Consequently, the user's location may not reflect their original location but rather the location of the server's IP.

Resolution for Anonymous IDs:

To address the issue of varying anonymous IDs, it's essential to retrieve the anonymous ID from cookies set on the browser side by the Usermaven tracking script on your marketing website. When making a service call using the Axios or Fetch library, ensure that you include this anonymous ID.

Below is an example snippet illustrating how to achieve this:

 
import axios from 'axios';
 
// Function to get the cookie value by its name
function getCookieValue(name) {
    const value = `; ${document.cookie}`;
    const parts = value.split(`; ${name}=`);
    if (parts.length === 2) return parts.pop().split(';').shift();
}
 
// Function to send a request with the anonymous id from the cookie
function sendRequestWithAnonymousId(url, requestData) {
    const anonymousId = getCookieValue('__eventn_id_UMWf7XBWPT');
    
    // Adding the anonymous id as a header or part of the request
    axios.post(url, requestData, {
        headers: {
            'Anonymous-Id': anonymousId
        }
    })
    .then(response => {
        console.log('Response:', response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });
}
 
sendRequestWithAnonymousId(exampleUrl, exampleData);
 

On the backend, you can handle the anonymous ID as follows (assuming PHP):

 
require_once('vendor/autoload.php');
 
use Segment\Segment;
 
// Initialize Segment with your write key
Segment::init('YOUR_WRITE_KEY');
 
// Function to get the anonymous ID from headers
function getAnonymousIdFromHeaders() {
    $headers = getallheaders();
    return $headers['Anonymous-Id'] ?? null;
}
 
// Get the anonymous ID
$anonymousId = getAnonymousIdFromHeaders();
 
// Send an event to Segment with the anonymous ID
Segment::track([
    "userId" => "userId123", // replace with actual user ID if available
    "event" => "Event Name",
    "properties" => [
        "property1" => "value1",
        "property2" => "value2"
    ],
    "context" => [
        "anonymousId" => $anonymousId
    ]
]);
 
// Flush the data to Segment
Segment::flush();

Resolution for the IP Address Issue:

To handle the issue of IP address discrepancies, in Laravel, you can pass the client's IP address to Segment using the analytics-php SDK. Extract the IP address from the Laravel request and include it in the event's context, as shown in the example code snippet:

 
use Segment\Segment;
 
// Initialize Segment with your write key
Segment::init('YOUR_WRITE_KEY');
 
// Get the client's IP address using Laravel's request helper
$clientIpAddress = request()->ip();
 
// Send an event to Segment with the client IP address
Segment::track([
    "userId" => "userId123", // replace with actual user ID if available
    "event" => "Event Name",
    "properties" => [
        "property1" => "value1",
        "property2" => "value2"
    ],
    "context" => [
        "ip" => $clientIpAddress
    ]
]);
 
// Flush the data to Segment
Segment::flush();

By implementing these solutions, you can ensure the correct transmission of data to Segment and Usermaven, resolving the identified issues. This approach guarantees accurate attribution when utilizing the Attribution report.

Additionally, you can enhance your data insights by populating the context object with additional information, as outlined in the Segment documentation. Key details such as Referrer, User Agent, locale, and more can be included. Refer to the Segment documentation here: Segment Docs - Context Object. (opens in a new tab)