Tracardi / tracardi

TRACARDI is a new HOME for your customer data. TRACARDI is an Composable API-first solution for any company that need inexpensive CDP to intergrate with.
https://www.tracardi.com
Other
521 stars 95 forks source link

Php sdk for tracking #38

Open atompie opened 3 years ago

atompie commented 3 years ago

Sdk in PHP, C# for tracardi track endpoint. SDK must be able to use /track endpoint to send new events to Tracardi.

Introduction

Endpoint /track is used to collect data in Tracardi. To register an event, connect to the /track endpoint on the server where Tracardi is installed.

You need to write a code that will connect to the POST method to the url e.g. http://tracardi.page.com/track and send the data about event plus additional information on the source and session. The purpose of this task is to write and SDK in C# or PHP to abstract connecting to /track.

Documentation

Please visit:

This will shed some light on /track endpoint

Visit this to get familiar with core terms

Track payload model

/track endpoint takes a payload. A model for that data can be found in:

Find

class TrackerPayload(BaseModel):
    source: Entity
    session: Entity

    metadata: Optional[Metadata]
    profile: Optional[Entity] = None
    context: Optional[dict] = {}
    properties: Optional[dict] = {}
    events: List[EventPayload] = []
    options: Optional[dict] = {}

This defines the body of POST request. You can see what parts are optional and what type they require. Notice that events requires a list of EventPayload.

class EventPayload(BaseModel):
    type: str
    properties: Optional[dict] = {}
    user: Optional[Entity] = None
    options: Optional[dict] = {}

Task

Write a PHP or C# SDK that models and sends data to /track endpoint.

bceyssens commented 2 years ago

@atompie we'll be working on a Drupal module for integrating with Tracardi: https://www.drupal.org/project/tracardi. At some point we'll be needing a PHP API client for fetching data from Tracardi, can we also help with that part of the project?

atompie commented 2 years ago

@bceyssens Sure. If you need help you can refer to:

or ask us any questions.

bceyssens commented 2 years ago

@atompie can you create the tracardi-php-sdk repository where we can work on?

atompie commented 2 years ago

@bceyssens Done https://github.com/Tracardi/tracardi-php-sdk

bceyssens commented 2 years ago

@atompie, thanks!

Aside from the /track endpoint we also need the possibility the fetch data from the /segments endpoint. I'm a bit confused with naming this an SDK and not an API client. Is there, in your eyes, a difference between the 2 or can we just add all API client functionality in the SDK?

These pages only include information about /track and /resource API endpoints:

This one looks like a clean solution https://gitlab.com/dropsolid/unomi-sdk-php, structure wise. They also mix the SDK and API client terms.

atompie commented 2 years ago

@atompie, thanks!

Aside from the /track endpoint we also need the possibility the fetch data from the /segments endpoint. I'm a bit confused with naming this an SDK and not an API client. Is there, in your eyes, a difference between the 2 or can we just add all API client functionality in the SDK?

@bceyssens API client is also fine. I would see it as a part of broader definition of SDK. As in python we have classes that do not use REST API but construct object for WroklowDefinition that is why I called it SDK. But API client is fine as long it interacts with API.

These pages only include information about /track and /resource API endpoints:

* https://github.com/atompie/tracardi-api/blob/master/manual/en/docs/integration/api-integration.md

* https://github.com/Tracardi/tracardi-python-sdk

Yes the python-sdk is not finished it has a lot of more functionality that is not exposed right now. I know you need a lot more to make and API Client. :) So there is a full REST API documentation at: http://localhost:8686/docs.

If you need fetching data from profile we have a GrapQL endpoint. It is still being developed so if you need more date in it let us know. We will make similar endpoints for events, sessions, etc.

http://localhost:8686/graphql/profile

This one looks like a clean solution https://gitlab.com/dropsolid/unomi-sdk-php, structure wise. They also mix the SDK and API client terms.

I looked at this and it looks fine. Very intuitive. I think we can go the same way.

bceyssens commented 2 years ago

@atompie I just created a first pull request: https://github.com/Tracardi/tracardi-php-sdk/pull/1. For now it only works for the /profile endpoint, but a basic structure has already been defined for others to work with. We want to continue with segments, but are encountering an error on validation: https://github.com/Tracardi/tracardi/issues/227