<commit_before>package mixpanel

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
	"time"
)

const (
	apiBaseURL = "https://api.mixpanel.com"
	library    = "vizzlo/mixpanel"
)

// actionSource describes where the call is originating from.
// This determines whether or not the location properties on a profile should be updated.
type actionSource int

const (
	// sourceUser flags the action as having originated with the user in question.
	sourceUser actionSource = iota
	// sourceScript means that the action originated in a backend script.
	// The IP should not be tracked in this case.
	sourceScript
)

// Client is a client to talk to the API
type Client struct {
	Token   string
	BaseURL string
	Client  http.Client
}

// Properties are key=value pairs that decorate an event or a profile.
type Properties map[string]interface{}

// Operation is an action performed on a user profile.
// Typically this is $set or $unset, but others are available.
type Operation struct {
	Name   string
	Values Properties
}

// New returns a configured client.
func New(token string) *Client {
	return &Client{
		Token:   token,
		BaseURL: apiBaseURL,
		Client: http.Client{
			Timeout: 60 * time.Second,
		},
	}
}

// Track sends event data with optional metadata.
func (m *Client) Track(distinctID string, event string, props Properties) error {
	if distinctID != "" {
		props["distinct_id"] = distinctID
	}
	props["token"] = m.Token
	props["mp_lib"] = library

	data := map[string]interface{}{"event": event, "properties": props}
	return m.makeRequestWithData("GET", "track", data, sourceUser)
}

func (m *Client) TrackAsScript(distinctID string, event string, props Properties) error {
	if distinctID != "" {
		props["distinct_id"] = distinctID
	}
	props["token"] = m.Token<commit_msg>Use reference for http.Client, set default timeout to 10s.<commit_after>package mixpanel

import (
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"strings"
	"time"
)

const (
	apiBaseURL = "https://api.mixpanel.com"
	library    = "vizzlo/mixpanel"
)

// actionSource describes where the call is originating from.
// This determines whether or not the location properties on a profile should be updated.
type actionSource int

const (
	// sourceUser flags the action as having originated with the user in question.
	sourceUser actionSource = iota
	// sourceScript means that the action originated in a backend script.
	// The IP should not be tracked in this case.
	sourceScript
)

// Client is a client to talk to the API
type Client struct {
	Token   string
	BaseURL string
	Client  *http.Client
}

// Properties are key=value pairs that decorate an event or a profile.
type Properties map[string]interface{}

// Operation is an action performed on a user profile.
// Typically this is $set or $unset, but others are available.
type Operation struct {
	Name   string
	Values Properties
}

// New returns a configured client.
func New(token string) *Client {
	return &Client{
		Token:   token,
		BaseURL: apiBaseURL,
		Client: &http.Client{
			Timeout: 10 * time.Second,
		},
	}
}

// Track sends event data with optional metadata.
func (m *Client) Track(distinctID string, event string, props Properties) error {
	if distinctID != "" {
		props["distinct_id"] = distinctID
	}
	props["token"] = m.Token
	props["mp_lib"] = library

	data := map[string]interface{}{"event": event, "properties": props}
	return m.makeRequestWithData("GET", "track", data, sourceUser)
}

func (m *Client) TrackAsScript(distinctID string, event string, props Properties) error {
	if distinctID != "" {
		props["distinct_id"] = distinctID
	}
	props["token"] = m.Token
{'fraction_non_alphanumeric': 0.10465429109496906, 'fraction_numerical': 0.0026903416733925207, 'mean_word_length': 3.9772423025435075, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2789070', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1136, 'n_words': 421}