scope3

package
v4.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

README ΒΆ

Scope3 RTD Module

This module integrates Scope3's Real-Time Data API to provide audience segments for targeting.

Maintainer

Configuration

YAML Configuration
hooks:
  enabled: true
  modules:
    scope3:
      rtd:
        enabled: true
        auth_key: ${SCOPE3_API_KEY}  # Set SCOPE3_API_KEY environment variable
        endpoint: https://rtdp.scope3.com/prebid/prebid
        timeout_ms: 1000
        cache_ttl_seconds: 60               # Cache segments for 60 seconds (default)
        add_to_targeting: false             # Set to true to add segments as individual targeting keys for GAM
        add_scope3_targeting_section: false # Also set targeting in dedicated scope3 section
        single_segment_key: ""              # When set, adds all segments as a comma separated value under a single targeting key
        masking:                            # Optional privacy masking configuration
          enabled: true                     # Enable field masking before sending to Scope3
          geo:
            preserve_metro: true      # Preserve DMA code (default: true)
            preserve_zip: true        # Preserve postal code (default: true)
            preserve_city: false      # Preserve city name (default: false)
            lat_long_precision: 2     # Lat/long decimal places: 0-4 (default: 2)
          user:
            preserve_eids:            # EID sources to preserve (default list below)
              - "liveramp.com"        # RampID
              - "uidapi.com"          # UID2
              - "id5-sync.com"        # ID5
          device:
            preserve_mobile_ids: false # Keep mobile advertising IDs (default: false)

  host_execution_plan:
    endpoints:
      /openrtb2/auction:
        stages:
          entrypoint:
            groups:
              - timeout: 5
                hook_sequence:
                  - module_code: "scope3.rtd"
                    hook_impl_code: "HandleEntrypointHook"
          auction_processed:
            groups:
              - timeout: 2000
                hook_sequence:
                  - module_code: "scope3.rtd"
                    hook_impl_code: "HandleAuctionProcessedHook"
          auction_response:
            groups:
              - timeout: 5
                hook_sequence:
                  - module_code: "scope3.rtd"
                    hook_impl_code: "HandleAuctionResponseHook"
JSON Configuration
{
  "hooks": {
    "modules": {
      "scope3": {
        "rtd": {
          "enabled": true,
          "endpoint": "https://rtdp.scope3.com/prebid/prebid",
          "auth_key": "your-scope3-auth-key",
          "timeout_ms": 1000,
          "cache_ttl_seconds": 60,
          "add_to_targeting": false,
          "add_scope3_targeting_section": false,
          "masking": {
            "enabled": true,
            "geo": {
              "preserve_metro": true,
              "preserve_zip": true,
              "preserve_city": false,
              "lat_long_precision": 2
            },
            "user": {
              "preserve_eids": ["liveramp.com", "uidapi.com", "id5-sync.com"]
            },
            "device": {
              "preserve_mobile_ids": false
            }
          }
        }
      }
    }
  }
}

Environment Variables

  • SCOPE3_API_KEY: Your Scope3 API key for authentication

Privacy Protection

This module includes comprehensive privacy masking to protect user data while preserving targeting capabilities. When masking is enabled, sensitive user information is removed or anonymized before being sent to the Scope3 API.

Field Masking Categories
🟒 ALWAYS SENT (Never Masked)

These fields are always passed through without modification as they are not considered sensitive:

Device Information

  • device.devicetype - Device type (mobile, desktop, CTV, etc.)
  • device.os - Operating system
  • device.osv - OS version
  • device.make - Device manufacturer
  • device.model - Device model
  • device.ua - User agent string
  • device.language - Language preference
  • device.connectiontype - Connection type (wifi, cellular, etc.)
  • device.js - JavaScript support
  • device.h/w - Screen dimensions
  • device.ppi - Screen PPI
  • device.pxratio - Pixel ratio

Geographic Information (Coarse)

  • geo.country - Country code (e.g., "US")
  • geo.region - State/region code (e.g., "CA")

Context Information

  • site.* - All site fields (domain, page, ref, etc.)
  • app.* - All app fields
  • imp.* - All impression data (ad sizes, positions, etc.)
πŸ”΄ NEVER SENT (Always Masked)

These fields are always removed for privacy protection:

Personal Identifiers

  • device.ip - IPv4 address
  • device.ipv6 - IPv6 address
  • user.id - Publisher's first-party user ID
  • user.buyeruid - Exchange-specific user ID
  • user.yob - Year of birth
  • user.gender - Gender
  • user.data - First-party data segments
  • user.keywords - User interest keywords

High-Precision Location

  • geo.accuracy - GPS accuracy radius
πŸ”§ CONFIGURABLE (With Defaults)

These fields can be configured to be preserved or masked:

Geographic Information (Fine-Grained)

Field Default Options Privacy Impact
geo.metro Preserved preserve/remove DMA code for regional targeting
geo.zip Preserved preserve/remove Postal code for local targeting
geo.city Removed preserve/remove City name
geo.lat/lon Truncated to 2 decimals 0-4 decimals or remove See precision guide below

User Identifiers

Field Default Options Notes
user.eids Filter to allowlist List of EID sources Default: ["liveramp.com", "uidapi.com", "id5-sync.com"]

Device Identifiers

Field Default Options Notes
device.ifa Removed preserve/remove Mobile advertising ID
device.dpidmd5 Removed preserve/remove Hashed device ID
device.dpidsha1 Removed preserve/remove Hashed device ID
Other device IDs Removed preserve/remove Various hashed identifiers
Geographic Precision Guide

When preserving latitude/longitude coordinates, the precision level has significant privacy implications:

Decimals Accuracy Privacy Level Use Case
0 Removed Maximum No location data
1 ~11 km Country/State Regional campaigns
2 ~1.1 km Neighborhood (Default) Store radius matching
3 ~111 m City block Dense urban targeting
4 ~11 m Building Maximum allowed

⚠️ WARNING: More than 4 decimal places can identify individuals and is not permitted by this module.

Configuration Examples
Maximum Privacy (Strict Mode)
masking:
  enabled: true
  geo:
    preserve_metro: false
    preserve_zip: false
    preserve_city: false
    lat_long_precision: 0
  user:
    preserve_eids: []
  device:
    preserve_mobile_ids: false
Balanced Privacy (Default)
masking:
  enabled: true
  geo:
    preserve_metro: true
    preserve_zip: true
    preserve_city: false
    lat_long_precision: 2
  user:
    preserve_eids: ["liveramp.com", "uidapi.com", "id5-sync.com"]
  device:
    preserve_mobile_ids: false
Retail/Commerce Optimization
masking:
  enabled: true
  geo:
    preserve_metro: true
    preserve_zip: true
    preserve_city: true
    lat_long_precision: 3  # Higher precision for store matching
  user:
    preserve_eids: ["liveramp.com", "retail-partner.com"]
  device:
    preserve_mobile_ids: true  # For in-store attribution
Privacy Compliance

GDPR Compliance

  • Removes direct identifiers by default
  • Configurable to meet legitimate interest requirements
  • Supports privacy-by-design principles

CCPA Compliance

  • Removes sale-related identifiers
  • Supports consumer privacy rights
  • Configurable per jurisdiction requirements

Industry Standards

  • Follows IAB OpenRTB privacy guidelines
  • Compatible with TCF 2.0 consent frameworks
  • Supports Privacy Sandbox initiatives

Features

  • Privacy-First Design: Comprehensive field masking to protect user data while preserving targeting
  • Flexible Masking: Configurable privacy controls for different use cases and compliance requirements
  • Real-Time Segments: Fetches audience segments from Scope3 API with intelligent caching
  • Thread-Safe Caching: Handles high-frequency requests with concurrent access protection
  • Identity Integration: Supports multiple identity providers (LiveRamp, UID2, ID5, etc.)
  • Geographic Privacy: Truncates location data to configurable precision levels
  • Graceful Degradation: Continues auction processing even when API errors occur
  • Performance Optimized: HTTP/2, connection pooling, and compression for high-traffic scenarios

Performance & Caching

This module implements intelligent caching and HTTP optimizations to handle high-frequency API requests:

  • Cache Key: Generated from user identifiers, site domain, and page URL
  • Cache Duration: Configurable via cache_ttl_seconds (default: 60 seconds)
  • Thread Safety: Uses read-write mutexes for concurrent access
  • Memory Efficiency: Stores only segment arrays, not full API responses
  • Frequency Cap Compatibility: Short 60-second default ensures frequency-capped segments are refreshed quickly
  • HTTP Optimization: Custom transport with connection pooling, HTTP/2, and compression for better performance

User Identity Integration

This module automatically detects and forwards available user identifiers from the bid request including:

  • LiveRamp identifiers (when available from publisher implementations or identity providers)
  • Publisher first-party user IDs
  • Device identifiers
  • Encrypted identity envelopes
Supported Identifier Types
  1. LiveRamp Identifiers (when available):

    • user.ext.eids[] array with source: "liveramp.com"
    • user.ext.rampid field (alternative location)
  2. Encrypted Identity Envelopes:

    • user.ext.liveramp_idl - ATS envelope location
    • user.ext.ats_envelope - Alternative envelope location
    • user.ext.rampId_envelope - Additional envelope location
    • ext.liveramp_idl - Request-level envelope
  3. Standard Identifiers:

    • user.id - Publisher user ID
    • device.ifa - Device identifier
    • Other standard OpenRTB identifiers
How It Works

The module forwards any fields that are not masked from the bid request to the Scope3 API (please see the Privacy Protection section for more details). Scope3's system can then utilize whatever identifiers are available for audience segmentation, whether they are resolved identifiers or encrypted envelopes that Scope3 may be able to process.

Note: The effectiveness of different identifier types depends on Scope3's integration capabilities and partnerships.

Data Output & Integration

Auction Response Data

The module adds audience segments to the auction response, giving publishers full control over how to use them:

  1. Publisher Flexibility: Segments are returned in ext.scope3.segments when configured for the publisher to decide where to send
  2. Google Ad Manager (GAM): Individual targeting keys are added when add_to_targeting: true (e.g., gmp_eligible=true)
  3. Other Ad Servers: Publisher can forward segments to any ad server or system
  4. Analytics: Segment data is available for reporting and analysis
Response Format Options

The module provides segments in two formats:

When add_scope3_targeting_section: true:

{
  "ext": {
    "scope3": {
      "segments": ["gmp_eligible", "gmp_plus_eligible"]
    }
  }
}

When add_to_targeting: true:

{
  "ext": {
    "prebid": {
      "targeting": {
        "gmp_eligible": "true",
        "gmp_plus_eligible": "true"
      }
    },
    "scope3": {
      "segments": ["gmp_eligible", "gmp_plus_eligible"]
    }
  }
}

This approach gives publishers maximum flexibility to:

  • Send segments to GAM via targeting keys
  • Forward to other ad servers or systems
  • Use for analytics and reporting
  • Control which segments go where based on their business logic

Documentation ΒΆ

Overview ΒΆ

Package scope3 implements a Prebid Server module for Scope3 RTD

Index ΒΆ

Constants ΒΆ

View Source
const DefaultScope3RTDURL = "https://rtdp.scope3.com/prebid/prebid"

Variables ΒΆ

This section is empty.

Functions ΒΆ

func Builder ΒΆ

func Builder(config json.RawMessage, deps moduledeps.ModuleDeps) (interface{}, error)

Builder is the entry point for the module This is called by Prebid Server to initialize the module

Types ΒΆ

type AEESignals ΒΆ

type AEESignals struct {
	Include []string            `json:"include,omitempty"`
	Exclude []string            `json:"exclude,omitempty"`
	Macro   string              `json:"macro,omitempty"` // base64
	Bidders []map[string]Bidder `json:"bidders,omitempty"`
}

type AsyncRequest ΒΆ

type AsyncRequest struct {
	*Module

	// For managing the lifecycle of the request
	// Context is used to pass to the request. This should be the context of the original request
	Context context.Context
	// Cancel can be called to cancel the request
	Cancel context.CancelFunc
	// DoneChannel will be closed when the request is done. When nil, no request was made
	Done chan struct{}

	// Response
	Segments []string
	Err      error
}

type Bidder ΒΆ

type Bidder struct {
	Segments []string `json:"segments,omitempty"`
	Deals    []string `json:"deals,omitempty"`
}

type Config ΒΆ

type Config struct {
	Endpoint                  string        `json:"endpoint"`
	AuthKey                   string        `json:"auth_key"`
	Timeout                   int           `json:"timeout_ms"`
	CacheTTL                  int           `json:"cache_ttl_seconds"`            // Cache segments for this many seconds
	CacheSize                 int           `json:"cache_size"`                   // Maximum size of segment cache in bytes
	AddToTargeting            bool          `json:"add_to_targeting"`             // Add segments as individual targeting keys
	AddScope3TargetingSection bool          `json:"add_scope3_targeting_section"` // Add segments as individual targeting keys in Scope3 targeting section
	Masking                   MaskingConfig `json:"masking"`                      // Privacy masking configuration
}

Config holds module configuration

type DeviceMaskingConfig ΒΆ

type DeviceMaskingConfig struct {
	PreserveMobileIds bool `json:"preserve_mobile_ids"` // Keep mobile advertising IDs (default: false)
}

DeviceMaskingConfig controls device data masking

type GeoMaskingConfig ΒΆ

type GeoMaskingConfig struct {
	PreserveMetro    bool `json:"preserve_metro"`     // DMA code (default: true)
	PreserveZip      bool `json:"preserve_zip"`       // Postal code (default: true)
	PreserveCity     bool `json:"preserve_city"`      // City name (default: false)
	LatLongPrecision int  `json:"lat_long_precision"` // Decimal places for lat/long (0-4, default: 2)
}

GeoMaskingConfig controls geographic data masking

type MaskingConfig ΒΆ

type MaskingConfig struct {
	Enabled bool                `json:"enabled"`
	Geo     GeoMaskingConfig    `json:"geo"`
	User    UserMaskingConfig   `json:"user"`
	Device  DeviceMaskingConfig `json:"device"`
}

MaskingConfig controls what user data is masked before sending to Scope3

type Module ΒΆ

type Module struct {
	// contains filtered or unexported fields
}

Module implements the Scope3 RTD module

func (*Module) HandleAuctionResponseHook ΒΆ

HandleAuctionResponseHook adds targeting data to the auction response

func (*Module) HandleEntrypointHook ΒΆ

HandleEntrypointHook initializes the module context with a sync.Map for storing segments

func (*Module) HandleProcessedAuctionHook ΒΆ

HandleRawAuctionHook is called early in the auction to fetch Scope3 data

func (*Module) NewAsyncRequest ΒΆ

func (m *Module) NewAsyncRequest(req *http.Request) *AsyncRequest

NewAsyncRequest creates a new AsyncRequest object The request's context is used to create a cancellable context for the async request and, which spans multiple hooks

type Scope3Response ΒΆ

type Scope3Response struct {
	AEESignals `json:"aee_signals"`
}

Response types for Scope3 API

type UserMaskingConfig ΒΆ

type UserMaskingConfig struct {
	PreserveEids []string `json:"preserve_eids"` // List of EID sources to preserve
}

UserMaskingConfig controls user data masking

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL