appsflyer

package module
v3.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 License: MIT Imports: 8 Imported by: 2

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 {
	Platform deviceOS
	Values   map[EventParam]string
	// 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 FakeTracker

type FakeTracker struct {
	FakeError        error
	ActualConfigPath string
	ActualEvent      *Event
}

func (*FakeTracker) Send

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

func (*FakeTracker) SetConfig

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

type Tracker

type Tracker interface {
	SetConfig(string) error
	Send(*Event) error
}

func NewTracker

func NewTracker() Tracker

Jump to

Keyboard shortcuts

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