➡️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

Request Body

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