Attributable SDKs

The Attributable SDKs allow for quick access to the Attributable APIs and are a good way of getting started on a custom integration.

As with the APIs, sub-incremental versions are forwards-compatible (e.g. 1.2 will accept the same parameters as 1.1), but incremental versions will not (e.g. 2.0 will require different configuration than 1.0). Also, as with the APIs, use of the SDKs requires a private, unique, application-specific access key. Please keep this key secure (e.g. do not add it to browser-viewable code).

The Attributable SDK is currently available just in PHP.



The Attributable SDK for PHP simplifies the process of interacting with the Attributable API. This version has been tested with version 1.0 of the API.

Download zip

Installation

To use the Attributable SDK, include the class file and then create an instance of the attributable class. The API key must be set.

include ' PATH /class_attributable.php';

$attributable = new attributable();
$attributable->key = ' KEY ';

Prudent use of the settings can minimize the syntax necessary when invoking a function within the class.

$attributable->settings['default_to_current_datetime'] = true;

Calling the various available APIs

There are public functions which correspond with each Attributable API. All functions have built-in defaults and/or error handling to ensure optimal interaction with the API. Diligent error management is strongly recommended to ensure that all data intended for the API is sent or otherwise handled appropriately.

$attributable->measure("Number of registrations", "+1");

if ($attributable['errors']) print_r($attributable->errors);

Returned values

Unlike the APIs themselves, which return a JSON result set, the SDK returns an associative array with two top-level keys: headers and content. The headers are useful for ascertaining the success or failure of the API connection, regardless of output. The content is an associative array which mirrors the JSON response from the API.

[headers] = "HTTP/1.0 200 Success\nContent-Type:application/json"
[response] = [
  [success] = [
    [event_id] = "123AbC"
  ]
]

If a given function in the SDK is unable to connect to the API for any reason, the function will return false in lieu of a full dataset, and errors will be accessible in plaintext through the [errors] array within the class. If the API connection is successful but the API itself returns errors or warnings (e.g. in the event of inappropriate input parameters), these errors are communicated through the dataset returned by the calling function.