Giter Site home page Giter Site logo

ahoy-ios's Introduction

Ahoy iOS

Simple visit-attribution and analytics library for Apple Platforms for integration with your Rails Ahoy backend.

๐ŸŒ– User visit tracking

๐Ÿ“ฅ Visit attribution through UTM & referrer parameters

๐Ÿ“† Simple, straightforward, in-house event tracking

Actions Status

Installation

The Ahoy library can be easily installed using Swift Package Manager. See the Apple docs for instructions on adding a package to your project.

Usage

To get started you need to initialize an instance of an Ahoy client. The initializer takes a configuration object, which requires you to provide a baseUrl as well as an ApplicationEnvironment object.

import Ahoy

let ahoy: Ahoy = .init(
    configuration: .init(
    environment: .init(
        platform: UIDevice.current.systemName,
        appVersion: "1.0.2",
        osVersion: UIDevice.current.systemVersion
    ),
    baseUrl: URL(string: "https://your-server.com")!
)

Configuration

The configuation object has intelligent defaults (listed below in parens), but allows you to a to provide overrides for a series of values:

  • visitDuration (30 minutes)
  • urlRequestHandler (URLSession.shared.dataTaskPublisher)
  • Routing
    • ahoyPath ("ahoy")
    • visitsPath ("visits")
    • eventsPath ("events")

Beyond configuration, you can also provide your own AhoyTokenManager and RequestInterceptors at initialization (requestInterceptors can be modified later) for custom token management and pre-flight Ahoy request modifications, respectively.

Tracking a visit

After your client is initialized โ€” ensure you maintain a reference โ€” you'll need to track a visit, typically done at application launch. If desired, you can pass custom data such as utm parameters, referrer, etc.

ahoy.trackVisit()
    .sink(receiveCompletion: { _ in }, receiveOutput: { visit in  print(visit) })
    .store(in: &cancellables)

Tracking events

After your client has successfully registered a visit, you can send begin to send events to your server.

ahoy.track(events: [myFirstEvent, mySecondEvent])
    .sink(receiveCompletion: { _ in }, receiveOutput: { _ in })
    .store(in: &cancellables)

Other goodies

To access the current visit directly, simply use your Ahoy client's currentVisit property. (There is also a currentVisitPublisher you can listen to.) Additionally, you can use the headers property to add Ahoy-Visitor and Ahoy-Visit tokens to your own requests as needed.

ahoy-ios's People

Contributors

ankane avatar namolnad avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.