Skip to main content

Samarth Analytics

First-Party Identity & ID Strategy for Server-Side Tracking Best Practices

FPID, HttpOnly first-party cookies, hashed-email as a persistent ID, and identity resolution that survives the cookieless transition.

By Samarth Analytics · Published · Updated · Server-Side Tracking · 11 min read

Summary: How to design durable first-party identity for server-side tracking. Covers client_id vs user_id vs FPID, setting HttpOnly + Secure server-side cookies, hashed email as a stable cross-session identifier, CDP-layer identity resolution, and privacy-safe retention.

  • TL;DR
    • First-party identity server-side tracking is crucial for accurate user identification in a cookieless future.
    • Relying solely on client_id can lead to significant data gaps and inaccuracies.
    • Implementing effective identity resolution requires managing three key identifiers: client_id, user_id, and a durable first-party ID (FPID).
    • Properly hashing emails and utilizing server-side cookies can enhance privacy compliance and user tracking.
    • Regularly revisit your identity strategies to ensure GDPR compliance and operational effectiveness.

Why client_id alone is not enough in a cookieless world

In the age of increasing privacy regulations and the decline of third-party cookies, relying on client_id alone for tracking user identity is insufficient. While client_id can uniquely identify users on your platform, it does not offer a complete picture of user behavior across multiple sessions, especially if users switch devices or browsers.

The limitations of client_id become evident when considering how users interact with your brand. In a cookieless environment, you lose the ability to follow users seamlessly throughout their journey. Users may clear their cookies, switch devices, or use private browsing modes, all of which can disrupt the tracking continuity provided by client_id.

To address this, we recommend developing a comprehensive first-party identity strategy that includes multiple identifiers to create a holistic view of user behavior and interactions.

The three identifiers every sGTM setup should manage

A robust server-side Google Tag Manager (sGTM) implementation should effectively manage three key identifiers:

  1. client_id: This is essential for identifying users within a single session. However, it only helps track behaviors at a more immediate level.
  2. user_id: This identifier links user interactions to specific accounts. It allows for enhanced personalization and engagement but requires a logged-in state to be effective.
  3. FPID (First-Party ID): This durable identifier is set through server-side tracking. It persists across sessions and helps stitch together user behavior over time, even when users are not logged in.

By managing these identifiers effectively, you can create a more seamless user experience and gain deeper insights into user behavior.

Creating a durable first-party cookie is essential for tracking users consistently across sessions. Here's how you can implement this with your server-side tracking:

  1. Generate FPID: Use a unique identifier for each user, such as crypto.randomUUID() in JavaScript.
  2. Set the cookie from the server: Ensure that the cookie has the HttpOnly, Secure, and SameSite=Lax attributes to enhance security and compliance.
  3. Cookie expiration: Aim for a max-age of at least two years to ensure the identifier remains valid for returning users.

Here's an example of how you can implement this in a custom server-side GTM template:

// Custom GTM Template Snippet
const { cookies } = require('cookies');

function getOrCreateFPID(request, response) {
  // Check for existing FPID cookie
  let fpid = cookies.get('FPID');

  // If FPID cookie doesn't exist, create a new one
  if (!fpid) {
    fpid = crypto.randomUUID();
    response.setHeader('Set-Cookie', `FPID=${fpid}; HttpOnly; Secure; SameSite=Lax; Max-Age=63072000`); // 2 years
  }
  
  return fpid;
}

// Example usage in your GTM server-side function
const fpid = getOrCreateFPID(req, res);

This code snippet demonstrates how to manage FPID cookies effectively, ensuring secure and compliant tracking.

Stitching anonymous session to logged-in user

Once users log in, it’s crucial to link their anonymous sessions to their logged-in user profiles. Here's how to achieve this:

  1. Capture session data: Store all relevant session data tied to the anonymous FPID.
  2. Upon login: Use the user_id to associate the anonymous session data with the logged-in user.
  3. Update records: Ensure that all future interactions are tied to the user_id, but retain the FPID for historical analysis.

By effectively stitching anonymous sessions to logged-in users, you can maintain continuity in user data, enabling better insights and reporting.

Hashed email as the backbone cross-session identifier

Using hashed emails as a cross-session identifier allows you to maintain user identity while complying with privacy regulations. Here’s how to implement this effectively:

  1. Hashing email: Use a strong hashing algorithm like SHA-256 to convert users' email addresses into a hash. This protects their privacy while allowing you to track unique users.
  2. Adding a pepper: To enhance security, use a secret pepper in combination with the hash. This adds an extra layer of protection against reverse engineering.

Tip: Hashing email with a pepper (not just plain SHA-256) is the industry-standard approach for using email as a stable cross-session identifier. It ensures that even if the hash is compromised, it cannot be easily reversed.

  1. Store hashed emails: Save the hashed email as a persistent identifier in your system, linking it with other identifiers like FPID and user_id.

Identity resolution in the CDP layer (or without one)

Identity resolution is crucial for understanding user behavior and ensuring accurate data collection. This can be achieved within a Customer Data Platform (CDP) or through custom implementations.

  1. With a CDP: Integrate your identifiers within the CDP to consolidate user data. This allows for better segmentation and targeting.
  2. Without a CDP: Implement custom logic to resolve identities by correlating FPID, user_id, and hashed emails. This may require additional development but can yield valuable insights.

In both scenarios, ensure that you maintain data integrity and user privacy throughout the process.

Privacy-safe retention and rotation of IDs

When managing identifiers, it's essential to balance user privacy with operational needs. Here’s how to retain and rotate IDs safely:

  1. Retention policy: Define a clear retention policy for your identifiers. Keep data only as long as necessary for analysis and marketing efforts.
  2. Regular rotation: Periodically rotate identifiers to minimize the risk of data exposure. For example, consider rotating FPID every 12-24 months.
  3. GDPR compliance: Ensure that all identifiers are treated according to GDPR guidelines, which means having a legal basis for processing pseudonymous data.

Warning: Treating ANY deterministic identifier (even hashed) as anonymous under GDPR carries regulatory risk - it is pseudonymous, which still requires a legal basis.

Common mistakes we see

Here are some common pitfalls when implementing first-party identity server-side tracking strategies:

  • Forgetting to rotate identifiers regularly, leading to stale data.
  • Not properly securing cookies with HttpOnly, Secure, and SameSite attributes.
  • Relying solely on client_id without integrating FPID and user_id.
  • Ignoring the need for a clear retention policy for identifiers.
  • Misunderstanding GDPR implications for hashed identifiers and pseudonymous data.
  • Failing to stitch anonymous sessions to logged-in users effectively.
  • Not utilizing hashed emails as stable cross-session identifiers.
  • Overlooking the importance of user privacy in data collection practices.

Implementation checklist

  • Define the identifiers you need to manage (client_id, user_id, FPID).
  • Implement server-side cookie settings for FPID with HttpOnly, Secure, and SameSite=Lax.
  • Create a hashing strategy for email addresses, using a strong algorithm and a pepper.
  • Develop a process for stitching anonymous sessions to logged-in users.
  • Establish a retention policy for identifiers and set a rotation schedule.
  • Ensure GDPR compliance for all identifiers, including pseudonymous data handling.
  • Regularly audit your identity resolution processes for effectiveness and compliance.
  • Train your team on best practices for managing user identifiers and privacy.

How Samarth Analytics helps

At Samarth Analytics, we specialize in helping businesses implement effective first-party identity strategies and server-side tracking solutions. Our team can conduct a free audit of your current setup, identifying areas for improvement and optimization. If you're ready to enhance your tracking capabilities and ensure compliance, contact us to discuss how we can support your goals.

All analytics guides · Markdown version of this guide