-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add track v2 support #64
Conversation
@krzaczek Everything looks pretty straightforward ! Here is the part I wanted to add to the documentation right before License. V2 Track APIThe Track API allows you to send entity-based operations to Customer.io. You can use it for both single operations and batch operations.
Single Entity OperationCreate or update a person entity.<?php
// Single entity operation
try {
$client->track->entity([
'type' => 'person',
'action' => 'identify',
'identifiers' => [
'id' => '123' // or 'email' => 'test@example.com' or 'cio_id' => 'cio_123'
],
'attributes' => [
'name' => 'John Doe',
'plan' => 'premium',
'test_attribute' => null, // pass null to remove the attribute from the entity
'last_activity_at' => time()
]
]);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle the error
} Create or update an object entity.<?php
// Create or update an object
try {
$client->track->entity([
'type' => 'object',
'action' => 'identify',
'identifiers' => [
'object_type_id' => 'product',
'object_id' => 'SKU-123'
],
'attributes' => [
'name' => 'Awesome Product',
'price' => 99.99,
'category' => 'Electronics'
]
]);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle the error
} Delete an entity<?php
// Delete an entity
try {
$client->track->entity([
'type' => 'person',
'action' => 'delete',
'identifiers' => [
'id' => '123'
]
]);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle the error
} Add relationships to a person<?php
// Add relationships to a person entity
try {
$client->track->entity([
'type' => 'person',
'action' => 'add_relationships',
'identifiers' => [
'id' => '123'
],
'cio_relationships' => [
'identifiers' => [
'object_type_id' => 'product',
'object_id' => 'SKU-123'
],
'relationship_attributes' => [
'role' => 'client',
'created_at' => '2024-01-01T10:12:00Z'
]
]
]);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle the error
} Batch Operations<?php
// Batch multiple operations
try {
$client->track->batch([
'batch' => [
[
'type' => 'person',
'action' => 'identify',
'identifiers' => ['id' => '123'],
'attributes' => ['name' => 'John Doe']
],
[
'type' => 'person',
'action' => 'event',
'identifiers' => ['id' => '123'],
'name' => 'purchased',
'timestamp' => time(),
'attributes' => ['product_id' => 'SKU-123']
],
[
'type' => 'object',
'action' => 'identify',
'identifiers' => [
'object_type_id' => 'product',
'object_id' => 'SKU-123'
],
'attributes' => ['in_stock' => true]
]
]
]);
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
// Handle the error
} Main differences with V1The Track V2 API introduces an entity-centric approach, contrasting with V1's action-based model. The key difference lies in the request structure:
This new approach provides a more intuitive way to interact with your data by focusing first on what entity you're working with before specifying what you want to do with it. It also allows the API to have only two endpoint for all operations. In theory, all v1 operations can be done with v2 but the v2 API does not support all v1 operations yet. For more details, see the Track V2 API documentation.
|
Add support for track v2 api #56