github.com/prebid/prebid-server/v2@v2.18.0/openrtb_ext/user.go (about)

     1  package openrtb_ext
     2  
     3  import (
     4  	"strconv"
     5  	"strings"
     6  
     7  	"github.com/prebid/openrtb/v20/openrtb2"
     8  )
     9  
    10  // ExtUser defines the contract for bidrequest.user.ext
    11  type ExtUser struct {
    12  	// Consent is a GDPR consent string. See "Advised Extensions" of
    13  	// https://iabtechlab.com/wp-content/uploads/2018/02/OpenRTB_Advisory_GDPR_2018-02.pdf
    14  	Consent string `json:"consent,omitempty"`
    15  
    16  	ConsentedProvidersSettings *ConsentedProvidersSettingsIn `json:"ConsentedProvidersSettings,omitempty"`
    17  
    18  	ConsentedProvidersSettingsParsed *ConsentedProvidersSettingsOut `json:"consented_providers_settings,omitempty"`
    19  
    20  	Prebid *ExtUserPrebid `json:"prebid,omitempty"`
    21  
    22  	Eids []openrtb2.EID `json:"eids,omitempty"`
    23  }
    24  
    25  // ExtUserPrebid defines the contract for bidrequest.user.ext.prebid
    26  type ExtUserPrebid struct {
    27  	BuyerUIDs map[string]string `json:"buyeruids,omitempty"`
    28  }
    29  
    30  type ConsentedProvidersSettingsIn struct {
    31  	ConsentedProvidersString string `json:"consented_providers,omitempty"`
    32  }
    33  
    34  type ConsentedProvidersSettingsOut struct {
    35  	ConsentedProvidersList []int `json:"consented_providers,omitempty"`
    36  }
    37  
    38  // ParseConsentedProvidersString takes a string formatted as Google's Additional Consent format and returns a list with its
    39  // elements. For instance, the following string "1~1.35.41.101" would result in []int{1, 35, 41, 101}
    40  func ParseConsentedProvidersString(cps string) []int {
    41  	// Additional Consent format version is separated from elements by the '~' character
    42  	parts := strings.Split(cps, "~")
    43  	if len(parts) != 2 {
    44  		return nil
    45  	}
    46  
    47  	// Split the individual elements
    48  	providerStringList := strings.Split(parts[1], ".")
    49  	if len(providerStringList) == 0 {
    50  		return nil
    51  	}
    52  
    53  	// Convert to ints and add to int array
    54  	var consentedProviders []int
    55  	for _, providerStr := range providerStringList {
    56  		if providerInt, err := strconv.Atoi(providerStr); err == nil {
    57  			consentedProviders = append(consentedProviders, providerInt)
    58  		}
    59  	}
    60  
    61  	return consentedProviders
    62  }