udetect

package module
v0.0.0-...-1dc5a0e Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 6 Imported by: 6

README

UDetect protocol

Build Status Go Report Card GoDoc Coverage Status

License Apache 2.0

The package describes the protocol of personal information detection to the integration of third-party service. This protocol designed for the common purposes using valuable for advertisers data at the same time there is no very sensitive for security reasons information about user person.

In the package, you will find the proto3 protocol description and prepared version for Golang and build script. You can use this protocol definitions to create your own user information service.

TODO

  • Add docker client example
  • Add minimal implementation of detector server
  • Provide minimal realisation with geo and device detection without user information
  • Add support UUID converter## License

LICENSE

Copyright 2024 Dmitry Ponomarev & Geniusrabbit

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const UndefinedCountryCode = "**"

UndefinedCountryCode 2 chars

Variables

View Source
var DeviceDefault = Device{Browser: &BrowserDefault, OS: &OSDefault}

DeviceDefault value

View Source
var GeoDefault = Geo{Country: UndefinedCountryCode, Carrier: &CarrierDefault}

GeoDefault value

Functions

func PrepareDomain

func PrepareDomain(domain string) (list []string)

PrepareDomain parts

func WithContext

func WithContext(ctx context.Context, cli *Client) context.Context

WithContext returns new context with client

Types

type App

type App struct {
	ExtID         string   `json:"eid,omitempty"`          // External ID
	Keywords      string   `json:"keywords,omitempty"`     // Comma separated list of keywords about the site.
	Cat           []string `json:"cat,omitempty"`          // Array of categories
	Bundle        string   `json:"bundle,omitempty"`       // App bundle or package name
	StoreURL      string   `json:"storeurl,omitempty"`     // App store URL for an installed app
	Ver           string   `json:"ver,omitempty"`          // App version
	Paid          int      `json:"paid,omitempty"`         // "1": Paid, "2": Free
	PrivacyPolicy int      `json:"pivacypolicy,omitempty"` // Default: 1 ("1": has a privacy policy)
}

App information

var AppDefault App

AppDefault object

func (*App) DomainPrepared

func (a *App) DomainPrepared() []string

DomainPrepared value

type Browser

type Browser struct {
	ID              uint64      `json:"id,omitempty"`    // Internal system ID
	Name            string      `json:"name,omitempty"`  //
	Version         string      `json:"ver,omitempty"`   //
	DNT             int         `json:"dnt,omitempty"`   // "1": Do not track
	LMT             int         `json:"lmt,omitempty"`   // "1": Limit Ad Tracking
	Adblock         int         `json:"ab,omitempty"`    // "1": AdBlock is ON
	PrivateBrowsing int         `json:"pb,omitempty"`    // "1": Private Browsing mode ON
	UA              string      `json:"ua,omitempty"`    // User agent
	Ref             string      `json:"r,omitempty"`     // Referer
	JS              int         `json:"js,omitempty"`    //
	Languages       []string    `json:"langs,omitempty"` //
	PrimaryLanguage string      `json:"lang,omitempty"`  // Browser language (en-US)
	FlashVer        string      `json:"flver,omitempty"` // Flash version
	Width           int         `json:"w,omitempty"`     // Window in pixels
	Height          int         `json:"h,omitempty"`     // Window in pixels
	IsRobot         int         `json:"rb,omitempty"`
	Extensions      []Extension `json:"extensions,omitempty"`
}

Browser base information structure

var BrowserDefault Browser

BrowserDefault value

type Carrier

type Carrier struct {
	ID   uint   `json:"id,omitempty"`      // Internal carrier ID
	Name string `json:"name,omitempty"`    //
	Code string `json:"carrier,omitempty"` //
}

Carrier base information structure

var CarrierDefault Carrier

CarrierDefault value

type Client

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

Client implementation fordata requests

func FromContext

func FromContext(ctx context.Context) *Client

FromContext returns client from context

func NewClient

func NewClient(tr Transport) *Client

NewClient for udetect API

func (*Client) Close

func (c *Client) Close() error

Close client connection

func (*Client) Detect

func (c *Client) Detect(ctx context.Context, req *Request) (*Response, error)

Detect user data information

type Device

type Device struct {
	ID         uint       `json:"id,omitempty"`             // Device ID
	Make       string     `json:"make,omitempty"`           // Device make
	Model      string     `json:"model,omitempty"`          // Device model
	OS         *OS        `json:"os,omitempty"`             // Device OS
	Browser    *Browser   `json:"browser,omitempty"`        // Device OS version
	ConnType   int        `json:"connectiontype,omitempty"` //
	DeviceType DeviceType `json:"devicetype,omitempty"`     //
	IFA        string     `json:"ifa,omitempty"`            // Native identifier for advertisers
	Height     int        `json:"h,omitempty"`              // Physical height of the screen in pixels.
	Width      int        `json:"w,omitempty"`              // Physical width of the screen in pixels.
	PPI        int        `json:"ppi,omitempty"`            // Screen size as pixels per linear inch.
	PxRatio    float64    `json:"pxratio,omitempty"`        // The ratio of physical pixels to device independent pixels.
	HwVer      string     `json:"hwv,omitempty"`            // Hardware version of the device (e.g., "5S" for iPhone 5S).
}

Device base information structure

type DeviceType

type DeviceType int

DeviceType object declaration

const (
	DeviceTypeUnknown   DeviceType = 0
	DeviceTypeMobile    DeviceType = 1
	DeviceTypePC        DeviceType = 2
	DeviceTypeTV        DeviceType = 3
	DeviceTypePhone     DeviceType = 4
	DeviceTypeTablet    DeviceType = 5
	DeviceTypeConnected DeviceType = 6
	DeviceTypeSetTopBox DeviceType = 7
	DeviceTypeWatch     DeviceType = 8
	DeviceTypeGlasses   DeviceType = 9
	DeviceTypeOOH       DeviceType = 10
)

RTB 5.17 Device Type

type Extension

type Extension struct {
	Name    string `json:"name,omitempty"`
	Version string `json:"ver,omitempty"`
}

Extension of some Browser/OS

type Geo

type Geo struct {
	ID            uint     `json:"id,omitempty"`            // Internal geo ID
	IP            net.IP   `json:"ip,omitempty"`            // IPv4/6
	Carrier       *Carrier `json:"carrier,omitempty"`       // Carrier or ISP derived from the IP address
	Lat           float64  `json:"lat,omitempty"`           // Latitude from -90 to 90
	Lon           float64  `json:"lon,omitempty"`           // Longitude from -180 to 180
	Country       string   `json:"country,omitempty"`       // Country using ISO 3166-1 Alpha 2
	Region        string   `json:"region,omitempty"`        // Region using ISO 3166-2
	RegionFIPS104 string   `json:"regionFIPS104,omitempty"` // Region of a country using FIPS 10-4
	Metro         string   `json:"metro,omitempty"`         //
	City          string   `json:"city,omitempty"`          //
	ZIP           string   `json:"zip,omitempty"`           //
	UTCOffset     int      `json:"utcoffset,omitempty"`     // Local time as the number +/- of minutes from UTC
}

Geo base information structure

func (*Geo) IPv4String

func (g *Geo) IPv4String() string

IPv4String string value

func (*Geo) IPv6String

func (g *Geo) IPv6String() string

IPv6String string value

func (*Geo) IsIPv6

func (g *Geo) IsIPv6() bool

IsIPv6 format

type OS

type OS struct {
	ID      uint   `json:"id"` // Internal system ID
	Name    string `json:"name,omitempty"`
	Version string `json:"ver,omitempty"`
}

OS base information structure

var OSDefault OS

OSDefault value

type Request

type Request struct {
	UDID            string      `json:"udid,omitempty"` // Advertisement Device ID (IDFA, AAID), Identifier for Advertising (IFA)
	UID             uuid.UUID   `json:"uid,omitempty"`
	SessID          uuid.UUID   `json:"sessid,omitempty"`
	IP              string      `json:"ip,omitempty"`
	UA              string      `json:"ua,omitempty"`
	URL             string      `json:"url,omitempty"`
	Ref             string      `json:"r,omitempty"`     // Referer
	DNT             int8        `json:"dnt,omitempty"`   // "1": Do not track
	LMT             int8        `json:"lmt,omitempty"`   // "1": Limit Ad Tracking
	Adblock         int8        `json:"ab,omitempty"`    // "1": AdBlock is ON
	PrivateBrowsing int8        `json:"pb,omitempty"`    // "1": Private Browsing mode ON
	JS              int8        `json:"js,omitempty"`    //
	Languages       []string    `json:"langs,omitempty"` //
	PrimaryLanguage string      `json:"lang,omitempty"`  // Browser language (en-US)
	FlashVer        string      `json:"flver,omitempty"` // Flash version
	Width           int         `json:"w,omitempty"`     // Window in pixels
	Height          int         `json:"h,omitempty"`     // Window in pixels
	Extensions      []Extension `json:"extensions,omitempty"`
}

Request object

type Response

type Response struct {
	User   *User   `json:"user"`
	Device *Device `json:"device"`
	Geo    *Geo    `json:"geo"`
}

Response object

type Site

type Site struct {
	ExtID         string   `json:"eid,omitempty"`          // External ID
	Domain        string   `json:"domain,omitempty"`       //
	Cat           []string `json:"cat,omitempty"`          // Array of categories
	PrivacyPolicy int      `json:"pivacypolicy,omitempty"` // Default: 1 ("1": has a privacy policy)
	Keywords      string   `json:"keywords,omitempty"`     // Comma separated list of keywords about the site.
	Page          string   `json:"page,omitempty"`         // URL of the page
	Referrer      string   `json:"ref,omitempty"`          // Referrer URL
	Search        string   `json:"search,omitempty"`       // Search string that caused naviation
	Mobile        int      `json:"mobile,omitempty"`       // Mobile ("1": site is mobile optimised)
}

Site information

var SiteDefault Site

SiteDefault info

func (*Site) DomainPrepared

func (s *Site) DomainPrepared() []string

DomainPrepared value

type Transport

type Transport interface {
	io.Closer
	Detect(ctx context.Context, req *protocol.Request) (*protocol.Response, error)
}

Transport interface defenition

type User

type User struct {
	UUID          uuid.UUID          `json:"uuid"`
	SessionID     string             `json:"sessid"`
	FingerPrintID string             `json:"fpid,omitempty"`
	ETag          string             `json:"etag,omitempty"`
	AgeStart      int                `json:"age_start,omitempty"` // Year of birth from
	AgeEnd        int                `json:"age_end,omitempty"`   // Year of birth to
	Keywords      string             `json:"keywords,omitempty"`  // Comma separated list of keywords, interests, or intent
	Interests     map[string]float64 `json:"interests,omitempty"` //
	Sex           map[int]float64    `json:"sex,omitempty"`       // 0 – undefined, 1 – man, 2 – woman
}

User object info

func (*User) Age

func (u *User) Age() int

Age middle of user

func (*User) MostPossibleSex

func (u *User) MostPossibleSex() int

MostPossibleSex detection

Directories

Path Synopsis
examples
server Module
Package protocol is a reverse proxy.
Package protocol is a reverse proxy.
transport

Jump to

Keyboard shortcuts

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