Download the PHP package onetracepro/onetrace-php without Composer

On this page you can find all versions of the php package onetracepro/onetrace-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package onetrace-php

OneTrace.pro PHP library

CI Packagist

Server-side integration with OneTrace.pro, the customer data platform: send events and orders, update profiles and consents, sync the product catalog, get recommendations, manage segments, journeys and campaigns, send transactional messages — the whole public API v1, without writing HTTP requests by hand.

Installation

Quick start

The first argument is the address of your account: https://cdp.onetrace.pro, or the domain of your white-label brand. Keys are created in the project under API keys. A write key is enough for events, but a server should send them with the secret key: purchases sent with the public write key do not award loyalty points, and their userId is dropped when the project requires signed user ids. The client sends events with the secret key whenever it has one. A secret key gets only the permissions chosen when it was created. Keep keys in environment variables and never send a secret key or the identity key to browsers.

Options

Option Default
write_key — cdp_wk_…: events, recommendations, widgets, Web Push
secret_key — cdp_sk_…: all methods; events go with it when it is set
identity_key — cdp_ik_…: the identity key of the project for signed user ids
timeout 10 seconds per request (built-in cURL transport)
connect_timeout 5 seconds to connect (built-in cURL transport)
max_retries 3 retries of network errors, 429 and 5xx; 0 disables
retry_delay 0.5 first backoff delay in seconds, doubled on every retry (up to 8 s); Retry-After wins
user_agent — appended to the User-Agent, e.g. my-shop/2.1
language en language of error messages from the API: en, ru, de, es, fr, it, pt, tr, uz, zh
http_client, request_factory, stream_factory — send through a PSR-18 client instead of cURL
transport cURL your own OneTrace\Http\Transport (tests, custom networking)

Events

Every message needs userId or anonymousId (alias needs userId and previousId, track needs event). The library adds messageId, timestamp (or formats a DateTimeInterface you pass) and context.library. Traits email, phone, telegram_chat_id and viber_id identify the profile; other traits become profile attributes; null deletes a trait. Calls return ['accepted' => 1, 'duplicates' => 0]: events are processed asynchronously.

Many events — batch() splits them into requests of up to 500 messages and 1 MB:

Buffer — queue events during a request or a job and send them in batches:

In long-running workers call flush() yourself. A failed flush() throws and keeps the messages; flushing again resends them with the same messageIds. Errors of the automatic flush at the end of the script are passed to the callback buffer(100, function (Throwable $e, array $lost) { … }), or reported as a PHP warning.

Signed user ids

The write key is public, so the platform cannot tell whether a userId from a browser belongs to the visitor. The website's server signs the id of the signed-in customer, and the tracker passes the signature with every request. Create the identity key in the project under Website → Connection → Server; once your website and apps sign user ids, turn on Require signature there.

Events sent with the secret key need no signature. Without a secret key, the client adds userHash to events and Web Push subscriptions with a userId itself.

Profiles

Identity types: user_id, anonymous_id, email, phone, telegram_chat_id, viber_id, web_push. Personal data in responses is masked unless the key has the profiles.pii permission.

Subscription preferences

The preference center of a profile: subscription topics by channel, frequency and pause of marketing messages. Use it for a «Subscriptions» block in your customer account, or link to the hosted page (preferences_url, signed, valid for 30 days):

Reading needs profiles.read, changing — profiles.write. Transactional messages are not affected.

Products and recommendations

Product ids are the same ids the website sends in events (product_id). Up to 1000 products per call. The description (HTML or text, sent as text up to 5000 characters) is what OneTrace AI answers shoppers' questions from on the product page («Ask AI», <div data-cdp-ask data-product-id="SKU-1"></div> with the tracker).

Translations for other languages of the store go with the product and the category; recommendations, widgets and search with language return names and links in that translation:

Product search

Word forms, typos and a query typed in the wrong keyboard layout are understood; with anonymousId (the tracker visitor id) the first results follow the visitor's interests. The plan of the project must include product search, and search requests count towards its monthly limit: over it the API answers 402 and PaymentRequiredException::getReason() is quota_exceeded — show the search of your website. With the search widget on, a results page can be just <div data-cdp-search-results data-cart-url="/cart/add/{id}"></div>: the tracker draws the results, facets and an "Add to cart" button that posts to your address and expects {"ok": true} or {"redirect": "…"}. A shop that renders the results page itself sends the search event once per query: (new Messages('myshop', $url))->search($customer, $query, $result['total']). With AI results, put <div data-cdp-search-ai="…"></div> above the products — an HTML-escaped JSON of url (the first results page), turns (the query, and the refinement if any), state, understood, refinements, relaxed from ai and products (ids in order): the tracker writes the short AI answer there and draws the chips; a removed chip, a refinement and "Regular search" open url with ai_state, ai_refine + ai_previous (base64url JSON) or ai=0, pass them back as state, the query and previous.

Segments, journeys and campaigns

Segment rules, journey graphs and campaign settings use the same JSON as the API reference.

Analytics

Reports of every kind with the same definitions as the analytics pages; the response holds the normalized definition and the result. Needs a secret key with analytics.read (30 report calculations per minute per key); saved reports and dashboards need analytics.write.

Also: report() (event report builder), retention(), paths(), savedReports() / iterateSavedReports(), savedReport(), updateSavedReport(), deleteSavedReport(), dashboards() / iterateDashboards(), dashboard(), updateDashboard(), deleteDashboard().

Loyalty

Points of the project's loyalty program at checkout and in the customer's account. Needs a secret key with loyalty.read (balance, history, calculation) or loyalty.write (holds, enrollment, adjustments).

A hold that is not confirmed returns to the balance in 30 minutes; refunds and cancellations of the order (order_refunded / order_cancelled) return the redeemed points automatically. Also: transactions() / iterateTransactions(), join() for programs with explicit enrollment.

Referrals: every member has a code and a link (referral_code, referral_url of the account). The tracker keeps the code of a ?ref= link in the cdp_ref cookie; pass it on registration:

Promo codes

Pools of promo codes: a shared code or unique codes issued to profiles in messages, journeys and through the API. The store applies the discount with its own coupon rule. Needs promo.read (pools, codes, checks) or promo.write (generate, upload, issue).

Use of a code is counted from the coupon property of the purchase event (Order of the Commerce module), cancellations free it.

Transactional messages

One message to a profile from a template — an order confirmation, a one-time code — or a cascade of channels tried in order. The profile is found by the identity or created. Needs a secret key with messages.send.

A transactional template skips consents, frequency limits and quiet hours, but not hard blocks of the channel (the address does not exist, the bot is blocked); other templates follow all messaging rules. integration_id is needed when the template's channel has several active integrations. Each recipient gets at most 20 messages an hour through the API (429 with Retry-After).

Store emails

The shop's own emails — order confirmations, registration, password resets, invoices — go out through the project's email integration as is, with delivery statuses and history in the customer profile. Order emails can be built from OneTrace templates instead (the store emails section): then send the order data, not the HTML. Needs a secret key with messages.send.

Chat conversations

Conversations of the online chat (website and messengers) for bots and external helpdesk systems. Reading needs a secret key with chats.read, answers and closing — chats.reply.

An answer through the API takes no operator seat: the operator inbox signs it with the name of the key (via: api, api_key), and the customer gets it in the website widget or in the messenger of the conversation. WhatsApp allows free text only within 24 hours of the customer's last message (ValidationException otherwise). A repeated idempotency key does not answer twice.

Store MCP server for the AI chat bot and AI shopping assistants

The AI chat bot of OneTrace can answer customers with live data of your store and, if you allow it, act on orders; AI shopping assistants can also place orders (contract v2, below). OneTrace calls your store's MCP server by the store MCP contract (order status, tracking, stock, delivery, returns, cancellation). OneTrace\StoreMcp\Server is a ready server: it checks the platform key, answers the MCP protocol, checks the customer token on customer tools and the customer's consent on actions. You implement only the tools you offer.

Orders from AI shopping assistants (contract v2)

AI shopping assistants (ChatGPT, Claude, Perplexity …) reach your catalog through the store MCP of OneTrace. With contract v2 they can also price and place an order in your store: the customer confirms the email or phone with a code, agrees to the items, address, delivery and total, and pays on your website by the payment link. Add two handlers to the same list:

Message templates

Templates have language versions: content in the main language, other languages in translations. Each recipient gets the version for the language trait of their profile, otherwise the main one.

E-commerce plugins

OneTrace\Commerce builds the messages of the common e-commerce contract that the OneTrace.pro shop plugins send (WooCommerce, Magento, PrestaShop, Shopware, OpenCart, 1C-Bitrix, CS-Cart). Use it for your own shop backend too: journeys, recommendations and predictions then work the same way.

Pagination

Lists return a OneTrace\Page (iterable, countable, getNextCursor()); iterate…() methods walk all pages lazily:

Errors

All exceptions implement OneTrace\Exception\OneTraceException.

Exception When
ValidationException (422) invalid request; getErrors() returns messages by field
AuthenticationException (401) missing, invalid or revoked key
PaymentRequiredException (402) the feature is not in the plan (getReason() = feature_unavailable, getFeature()) the project is read-only after the trial or the payment grace period (subscription_expired), or a monthly limit of the plan is spent (quota_exceeded, e.g. search requests)
PermissionException (403) the key lacks a permission, the site domain is not allowed or the account is suspended
NotFoundException (404) not found in the key's project
ConflictException (409) the current state does not allow the action
RateLimitException (429) rate limit or monthly event quota; getRetryAfter()
ServerException (5xx) temporary server error
ApiException any other error status; base class of the above, getStatusCode(), getPayload()
TransportException no response: DNS, connection, TLS, timeout
ConfigurationException a method needs a key the client was not given

Network errors, 429, 5xx (and 409 of a request with an idempotency key) are retried before the exception is thrown. Invalid arguments (a track without event, an unknown identity type) throw InvalidArgumentException before any request.

Idempotency

Retries never duplicate data: events carry a messageId (pass your own, such as an order number, to make resending from your side safe too); creating segments, journeys and campaigns, adding segment members, enrolling and launching send an Idempotency-Key — generated per call and reused on retries, or your own as the last argument:

PSR-18 clients

Testing your code

Pass a transport implementing OneTrace\Http\Transport to record requests and return prepared responses instead of calling the API.

Development

The test suite checks that every operation of the API specification has a method (tests/OperationsTest.php); ONETRACE_SPEC_URL=https://cdp.onetrace.pro/api/v1/openapi.json vendor/bin/phpunit --filter OperationsTest runs it against the live platform.

License

MIT, see LICENSE.


All versions of onetrace-php with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package onetracepro/onetrace-php contains the following files

Loading the files please wait ...