➡️Custom Events API

For more detailed understanding of how users interact with your application, you can track custom events across your application by sending us Custom Events via our API at https://spindl.link/events/server.

To do this, you will need:

  • Spindl API Key

  • Properly Formatted events (you can send individual event or an array)

    • for each event, you can define an object:

[
  {
   "type": "CUSTOM", // required (use the default "CUSTOM")
   "data": {
     "name": "Your Event Name", // required.
     "properties": { ... } // optional data can be passed as JSON here
   },
   "identity": {
      // either address or customerUserId is required to help us identify a user
      "address": "0x...",
      "customerUserId": "test@gmail.com"
   }
  }
]

Below are several examples for sending an array of events to our API:

Send Custom Events

POST https://spindl.link/events/server

Sending Custom events via API

Headers

NameTypeDescription

X-API-Key*

String

The API token

Request Body

NameTypeDescription

*

Array

array of events is required to be passed in. Please pass in a array of objects with the following keys: type (required): string

use "CUSTOM" here name (required): string

Min 3 & max 100 characters. Must be lower/uppercase alphanumeric. _:- symbols & spaces are allowed

properties (optional): Object

Must be a valid JSON object. Max size 16KB & object keys & values cannot exceed 1,000 characters

identity: { address: string (required)

customerUserId: string (required) } : either address or customerUserId is required to help us identify a user.

address must be a valid wallet address.

cusomerUserId can be a unique db user id or a unique identifier like email address.

These identifiers are very important part of stitching identities and providing accurate attribution.

NodeJs Axios Example
const axios = require('axios');
let data = JSON.stringify([
  {
    "type": "CUSTOM",
    "data": {
      "name": "ADD_TO_CART",
      "properties": {
        "optional_data": "here"
      }
    },
    "identity": {
      "address": "0x0000000000000000000000000000000000000000",
      "customerUserId": "test@gmail.com"
    }
  },
  {
    "type": "CUSTOM",
    "data": {
      "name": "TEST_EVENT_2",
      "properties": {
        "optional_data": "here"
      }
    },
    "identity": {
      "address": "0x0000000000000000000000000000000000000000"
    }
  }
]);

let config = {
  method: 'post',
  url: 'https://spindl.link/events/server',
  headers: { 
    'X-Api-Key': 'YOUR_API_KEY', 
    'Content-Type': 'application/json',
  },
  data : data
};

axios.request(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Javascript Fetch Example
var myHeaders = new Headers();
myHeaders.append("X-Api-Key", "YOUR_API_KEY");
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify([
  {
    "type": "CUSTOM",
    "data": {
      "name": "ADD_TO_CART",
      "properties": {
        "optional_data": "here"
      }
    },
    "identity": {
      "address": "0x0000000000000000000000000000000000000000",
      "customerUserId": "test@gmail.com"
    }
  },
  {
    "type": "CUSTOM",
    "data": {
      "name": "TEST_EVENT_2",
      "properties": {
        "optional_data": "here"
      }
    },
    "identity": {
      "address": "0x0000000000000000000000000000000000000000",
      "customerUserId": "test@gmail.com"
    }
  }
]);

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://spindl.link/events/server", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
cURL Example
curl --location 'https://spindl.link/events/server' \
--header 'X-Api-Key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '[
    {
        "type": "CUSTOM",
        "data": {
            "name": "ADD_TO_CART",
            "properties": {
                "optional_data": "here"
            }
        },
        "identity": {
            "address": "0x0000000000000000000000000000000000000000",
            "customerUserId": "test@gmail.com"
        }
    },
    {
        "type": "CUSTOM",
        "data": {
            "name": "TEST_EVENT_2",
            "properties": {
                "optional_data": "here"
            }
        },
        "identity": {
            "address": "0x0000000000000000000000000000000000000000"
        }
    }
]'

Last updated