Help us shape the future of Go! Take the 2026 Go Developer Survey

appsflyer

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 8 Imported by: 0

README

appsflyer-go

A Go client library for the AppsFlyer Server-to-Server Events API

Installation

go get github.com/carpenterscode/appsflyer-go

Configuration

Set up the client with a JSON file of this format

[
    {
        "appId": "com.company.android",
        "devKey": "aaaaaaaaaaaaaaaaaaaaaa",
        "platform": "android"
    },
    {
        "appId": "id111111111",
        "bundleId": "com.company.ios",
        "devKey": "aaaaaaaaaaaaaaaaaaaaaa",
        "platform": "ios"
    }
]

Usage

import (
        "time"

        af "github.com/carpenterscode/appsflyer-go"
)

func main() {
        tracker, trackErr := af.NewTracker()
        if trackErr != nil {
                panic(trackErr)
        }
        tracker.SetConfig("appsflyer.json")

        startTrial(tracker)

        subscribe(tracker)

        cancelSubscription(tracker)
}

func startTrial(tracker af.Tracker) {

        // User starts a trial
        evt := af.NewEvent("1111111111111-1111111", af.IOS).
                SetName(af.StartTrial).
                SetAdvertisingID("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA").
                SetDeviceIP("1.2.3.4").
                SetPrice(59.99, "USD").
                SetDateValue("expiry", validDate).
                SetEventTime(time.Now())

        if err := tracker.Send(evt); err != nil {
                panic(err)
        }
}

func subscribe(tracker af.Tracker) {

        // User ends trial and pays for first subscription period
        evt := af.NewEvent("1111111111111-1111111", af.IOS).
                SetName(af.Subscribe).
                SetAdvertisingID("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA").
                SetDeviceIP("1.2.3.4").
                SetRevenue(59.99, "USD").
                SetDateValue("expiry", validDate).

        if err := tracker.Send(evt); err != nil {
                panic(err)
        }
}

func cancelSubscription(tracker af.Tracker) {

        // User cancels a subscription
        evt := af.NewEvent("1111111111111-1111111", af.Android)
        evt.SetName(af.EventName("cancel_subscription"))
        evt.SetRevenue(-59.99, "USD")

        if err := tracker.Send(evt); err != nil {
                panic(err)
        }
}

Documentation

Official AppsFlyer docs

License

MIT

Documentation

Index

Constants

View Source
const (
	Android deviceOS = "android"
	IOS     deviceOS = "ios"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event added in v1.2.1

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

func NewEvent

func NewEvent(appsFlyerID string, platform deviceOS) *Event

func (Event) MarshalJSON added in v1.2.1

func (evt Event) MarshalJSON() ([]byte, error)

func (*Event) SetAdvertisingID added in v1.2.1

func (evt *Event) SetAdvertisingID(advertisingID string) *Event

func (*Event) SetDateValue added in v1.2.1

func (evt *Event) SetDateValue(param EventParam, val time.Time) *Event

func (*Event) SetDeviceIP added in v1.2.1

func (evt *Event) SetDeviceIP(deviceIP string) *Event

func (*Event) SetEventTime added in v1.2.1

func (evt *Event) SetEventTime(eventTime time.Time) *Event

func (*Event) SetName added in v1.2.1

func (evt *Event) SetName(name EventName) *Event

func (*Event) SetPrice added in v1.2.1

func (evt *Event) SetPrice(price float64, currency string) *Event

func (*Event) SetRevenue added in v1.2.1

func (evt *Event) SetRevenue(revenue float64, currency string) *Event

func (*Event) SetValue added in v1.2.1

func (evt *Event) SetValue(param EventParam, val string) *Event

type EventName

type EventName string
const (
	StartTrial EventName = "af_start_trial"
	Subscribe  EventName = "af_subscribe"
)

type EventParam

type EventParam string
const (
	ParamRevenue  EventParam = "af_revenue"
	ParamPrice    EventParam = "af_price"
	ParamCurrency EventParam = "af_currency"
)

type Tracker

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

func NewTracker

func NewTracker() (*Tracker, error)

func (Tracker) Send

func (t Tracker) Send(evt *Event) error

func (*Tracker) SetConfig

func (t *Tracker) SetConfig(configPath string) error

Jump to

Keyboard shortcuts

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