Giter Club home page Giter Club logo

customerio's Introduction

Customer.io API Client

PHP bindings for the Customer.io API.

API Documentation

Build Status Code Climate Test Coverage

There are two primary API hosts available for to integrate with:

Behavioral Tracking

https://track.customer.io/api/v1/
Behavioral Tracking API is used to identify and track customer data with Customer.io.

API

https://api.customer.io/v1/api/
API allows you to read data from your Customer.io account for use in custom workflows in your backend system or for reporting purposes.

API (BETA)

https://beta-api.customer.io/v1/api/
Beta API features should be used with caution, and should be expected to change with little notice. Please refer to this documentation for available endpoints.

Installation

The API client can be installed via Composer.

In your composer.json file:

{
    "require": {
        "printu/customerio": "~3.0"
    }
}

Once the composer.json file is created you can run composer install for the initial package install and composer update to update to the latest version of the API client.

The client uses Guzzle.

Basic Usage

Remember to include the Composer autoloader in your application:

<?php
require_once 'vendor/autoload.php';

// Application code...
?>

Configure your access credentials when creating a client:

<?php
use Customerio\Client;

$client = new Client('YOUR_API_KEY', 'YOUR_SITE_ID');
?>

Local Testing

Run phpunit from the project root to start all tests.

Examples

Customers

<?php
// Create customer
try {
    $client->customers->add(
        [
            'id' => 1,
            'email' => '[email protected]',
            'plan' => 'free',
            'created_at' => time()
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

// Get customer
try {
    $client->customers->get(
        [
            'email' => '[email protected]',        
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

// Update customer
try {
    $client->customers->update(
        [
            'id' => 1,
            'email' => '[email protected]',
            'plan' => 'premium'
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error   
}

// Delete customer
try {
    $client->customers->delete(
        [
            'id' => 1,
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error   
}

Events

<?php
// Add customer event
try {
    $client->customers->event(
        [
            'id' => 1,
            'name' => 'test-event',
            'data' => [
                'event-metadata-1' => 'test',
                'event-metadata-2' => 'test-2'
            ]
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

// Add anonymous event
try {
    $client->events->anonymous(
        [
            'name' => 'invite-friend',
            'data' => [
                'recipient' => '[email protected]'
            ]
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

Anonymous event example usage.

Segments

<?php
// Get segment data
try {
    $client->segments->get(
        [
            'id' => 1
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

Check for other available methods here

PageView

<?php
// Add page view
try {
    $result = $client->page->view(
        [
            'id' => 1,
            'url' => 'http://example.com/login',
            'data' => [
                'referrer' => 'http://example.com'
            ]
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

Campaigns

<?php
// Get campaigns data
try {
    $client->campaigns->get(
        [
            'id' => 1
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

Check for other available methods here

<?php
// Trigger broadcast campaign
try {
    $result = $client->campaigns->trigger(
        [
            'id' => 1,
            'data' => [
                'headline' => 'Roadrunner spotted in Albuquerque!',
                'date' => 'January 24, 2018', 
                'text' => 'We\'ve received reports of a roadrunner in your immediate area! Head to your dashboard to view more information!' 
            ],
            'recipients' => [
                'segments' => [
                    'id' => 1
                ]
            ]
        ]
    );
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // Handle the error
}

See here for more examples of API Triggered Broadcasts

License

MIT license. See the LICENSE file for more details.

customerio's People

Contributors

jbardnz avatar krzaczek 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.