Table of Contents

Go SDK

The Go SDK from vektorone.co lets you integrate intelligent ad generation into your Go-based chat or web systems. It enables you to:

All SDK functions use idiomatic Go error handling.

Installation

Install the SDK:

go get github.com/goodguysoft/adselect-go

Import in your application:

import adselect "github.com/goodguysoft/adselect-go"

Sending Chat History

Use `SendChatHistory()` to send complete conversation data to the API.

Function Signature

func SendChatHistory(apiId string, apiKey string, userID string, conversationID string, messages []adselect.ChatMessage) error

Parameters

Message Format

type ChatMessage struct {
    Role string // "User" or "Bot"
    Text string // Message content
}

Example

messages := []adselect.ChatMessage{
    {Role: "User", Text: "I'm looking for dog food."},
    {Role: "Bot", Text: "We have natural dog food options."},
}
 
err := adselect.SendChatHistory("YOUR_API_ID", "YOUR_API_KEY", "user-123", "conv-456", messages)
if err != nil {
    log.Fatalf("failed to send chat history: %v", err)
}

Getting Ad for a Chat Session

Use `GetChatAd()` to fetch an ad based on chat context.

Function Signature

func GetChatAd(apiId string, apiKey string, userID string, conversationID string, adType string, jsFunc string) (string, error)

Parameters

Example

adHtml, err := adselect.GetChatAd("YOUR_API_ID", "YOUR_API_KEY", "user-123", "conv-456", adselect.AdTypeHtmlTextAd, "")
if err != nil {
    log.Printf("failed to get ad: %v", err)
} else {
    fmt.Println("Ad HTML:", adHtml)
}

Getting Ad for a Web Page

Use `GetPageAd()` to retrieve an ad based on HTML page content.

Function Signature

func GetPageAd(apiId string, apiKey string, pageContent string, adType adsdk.AdType, jsFunc string) (string, error)

Parameters

Example

html := "<html><body><h1>Best dog food 2024</h1><p>Our guide covers natural ingredients...</p></body></html>"
 
adScript, err := adsdk.GetPageAd("YOUR_API_ID", "YOUR_API_KEY", html, adsdk.AdTypeJavaScript, "renderAd")
if err != nil {
    log.Printf("ad error: %v", err)
} else {
    fmt.Println("<script>" + adScript + "</script>")
}

AdType Constants

const (
    AdTypeJsonText              = "JsonText"
    AdTypeJsonImage             = "JsonImage"
    AdTypeHtmlText              = "HtmlTextAd"
    AdTypeHtmlImage             = "HtmlImageAd"
    AdTypeJavaScriptText        = "JavaScriptTextAd"
    AdTypeJavaScriptImage       = "JavaScriptImageAd"
    AdTypeBannerMediumRectJson  = "BannerMediumRectJson"
    AdTypeBannerMediumRectHtml  = "BannerMediumRectHtml"
    AdTypeBannerLeaderboardJson = "BannerLeaderboardJson"
    AdTypeBannerLeaderboardHtml = "BannerLeaderboardHtml"
    AdTypeBannerWideSkyJson     = "BannerWideSkyJson"
    AdTypeBannerWideSkyHtml     = "BannerWideSkyHtml"
)

Error Handling

All functions return a standard Go `error` type.

Always validate return values using:

if err != nil {
    // handle failure
}

See Also