metaconvapi

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

metaconvapi

Minimal Meta Conversion API client for golang

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashString

func HashString(input string) string

HashString SHA256 hashes a string

Types

type MetaCAClient

type MetaCAClient struct {
	PixelID      string
	AccessToken  string
	ActionSource string
	Currency     string
	HTTPClient   *http.Client
}

MetaCAClient handles communication with Meta Conversions API

func NewMetaCAClient

func NewMetaCAClient(pixelID, accessToken, actionSource, currency string, timeout time.Duration) *MetaCAClient

NewMetaCAClient creates a new client instance

func (*MetaCAClient) SendAddToCartEvent

func (c *MetaCAClient) SendAddToCartEvent(
	userID, email, phone string,
	req *http.Request,
	productID string, quantity int, consentAvail bool,
) error

SendAddToCartEvent builds and sends a single AddToCart event

func (*MetaCAClient) SendEvents

func (c *MetaCAClient) SendEvents(events []MetaConversionEvent) (*MetaCAPIResponse, error)

SendEvents sends events to Meta Conversions API

func (*MetaCAClient) SendPageViewEvent

func (c *MetaCAClient) SendPageViewEvent(
	userID, email string,
	req *http.Request,
	pageURL string,
	consentAvail bool,
) error

SendPageViewEvent builds and sends a single PageView event

func (*MetaCAClient) SendPurchaseEvent

func (c *MetaCAClient) SendPurchaseEvent(
	userID, email, phone, orderID string,
	req *http.Request,
	items []MetaContent, total float64,
	consentAvail bool,
) error

SendPurchaseEvent builds and sends a single Purchase event

func (*MetaCAClient) SendSearchEvent

func (c *MetaCAClient) SendSearchEvent(
	userID, email, phone string,
	req *http.Request,
	searchString string,
	consentAvail bool,
) error

SendSearchEvent builds and sends a single Search event

func (*MetaCAClient) SendTestEvent

func (c *MetaCAClient) SendTestEvent(userEmail string, userPhone string, eventId string, req *http.Request, consentAvail bool) error

SendTestEvent sends a test event

func (*MetaCAClient) SendViewContentEvent

func (c *MetaCAClient) SendViewContentEvent(
	userID, email, phone string,
	req *http.Request,
	contentCategory, contentName string,
	consentAvail bool,
) error

SendViewContentEvent builds and sends a single ViewContent event

type MetaCAPIRequest

type MetaCAPIRequest struct {
	Data []MetaConversionEvent `json:"data"`
}

MetaCAPIRequest is the wrapper for the API call

type MetaCAPIResponse

type MetaCAPIResponse struct {
	EventsReceived int `json:"events_received"`
	Messages       []struct {
		Level   string `json:"level"`
		Message string `json:"message"`
	} `json:"messages,omitempty"`
}

MetaCAPIResponse is the API response structure

type MetaContent

type MetaContent struct {
	ID       string  `json:"id"`
	Name     string  `json:"name"`
	Quantity int     `json:"quantity"`
	Price    float64 `json:"price,omitempty"`
}

MetaContent represents an item in the cart/purchase

type MetaConversionEvent

type MetaConversionEvent struct {
	EventName             string         `json:"event_name"`
	EventTime             int64          `json:"event_time"`
	ActionSource          string         `json:"action_source"`
	EventID               string         `json:"event_id,omitempty"`
	UserData              MetaUserData   `json:"user_data"`
	CustomData            MetaCustomData `json:"custom_data,omitempty"`
	DataProcessingOptions []string       `json:"data_processing_options,omitempty"`
}

MetaConversionEvent represents a single event to send to Meta

type MetaCustomData

type MetaCustomData struct {
	Currency string                 `json:"currency,omitempty"`
	Value    float64                `json:"value,omitempty"`
	Contents []MetaContent          `json:"contents,omitempty"`
	OrderID  string                 `json:"order_id,omitempty"`
	Extra    map[string]interface{} `json:"-"`
}

MetaCustomData contains event-specific parameters

type MetaUserData

type MetaUserData struct {
	Em              string `json:"em,omitempty"` // hashed email
	Ph              string `json:"ph,omitempty"` // hashed phone
	ClientIPAddress string `json:"client_ip_address,omitempty"`
	ClientUserAgent string `json:"client_user_agent,omitempty"`
	Fbp             string `json:"fbp,omitempty"`
	Fbc             string `json:"fbc,omitempty"`
}

MetaUserData contains hashed user identifiers

Jump to

Keyboard shortcuts

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