Skip to content

nikon72ru/yandex-audience-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yandex-audience-api

Yandex Audience Api with Golang

Supported methods

Entity Method Support
Pixels List of pixels ✔️
Pixels Create pixel ✔️
Pixels Update pixel ✔️
Pixels Remove pixel ✔️
Pixels Restore pixel ✔️
Delegates List of delegates ✔️
Delegates Create delegate ✔️
Delegates Remove delegate ✔️
Accounts List of accounts ✔️
Grants List of grants ✔️
Grants Create grant ✔️
Grants Remove grant ✔️
Segments Segments list ✔️
Segments Create "pixel" segment ✔️
Segments Create "lookalike" segment ✔️
Segments Create segment from metrika ✔️
Segments Create segment from app metrika ✔️
Segments Create geo-circle segment ✔️
Segments Create geo-polygons segment ✔️
Segments Create segment from file ✔️
Segments Create segment from csv ✔️
Segments Save uploaded segment ✔️
Segments Update segment ✔️
Segments Remove segment ✔️
Segments Reprocess segment ✔️
Segments Update coords in geo-circle segment
Segments Save uploaded ClientID segment
Segments Update uploaded segment

Quickstart

package main

import (
	"context"
	"fmt"
	"github.com/nikon72ru/yandex-audience-api/audience"
	"log"
)

func main() {
	//Creating audience client
	client, _ := audience.NewClient(context.Background())
	//Get all my segments
	allMySegments, _ := client.SegmentsList()
	_ = allMySegments

	//Create segment
	var segment = audience.CircleGeoSegment{
		BaseSegment: audience.BaseSegment{
			Name: "My new segment",
		},
		GeoSegmentType: "work",
		TimesQuantity:  20,
		PeriodLength:   30,
		Radius:         500,
		Points: []audience.Point{{
			Latitude:    65.534102,
			Longitude:   57.157753,
			Description: "random point",
		}}}
	if err := client.CreateCircleGeoSegment(&segment); err != nil {
		log.Fatal(err)
	}

	//Check ID of created segment
	fmt.Println(segment.ID)

	//Updating created segment
	segment.Name = "My updated segment"
	if err := client.UpdateSegment(segment.ID, &segment); err != nil {
		log.Fatal(err)
	}

	//Remove segment
	if err := client.RemoveSegment(segment.ID); err != nil {
		log.Fatal(err)
	}

}

Token

There are two ways to specify your token.

1. As environment variable "YANDEX_AUDIENCE_TOKEN":
export YANDEX_AUDIENCE_TOKEN=[YOUR TOKEN]
2. In context:
func main() {
	//Creating audience client
	client, _ := audience.NewClient(context.WithValue(context.Background(), "YANDEX_AUDIENCE_TOKEN", "[YOUR TOKEN]"))
	//Your another cool code
}

Segment from file

You can upload files with minimal buffering on server side

- Notice! You need to save segment after uploading
func main() {
	//Creating audience client
	client, _ := audience.NewClient(context.Background())

	var segment = audience.UploadingSegment{
		BaseSegment: audience.BaseSegment{
			Name: "segment from file",
		},
		Hashed:      false,
		ContentType: audience.Mac,
	}
	//upload file
	if err := client.CreateFileSegment(&segment, "./test-files/macs_for_uploads.csv"); err != nil {
		log.Fatal(err)
	}

	//Save uploaded segment
	if err := client.SaveUploadedSegment(&segment); err != nil {
		log.Fatal(err)
	}
}

CreateCSVSegment() and CreateReaderSegment() methods also supported


Any questions?

Welcome to create issue!