Client-side setup

Learn how to set up the client-side SDK.

The PHP SDK runs on the server, where it fetches content and evaluates queries. Client-side concerns, such as tracking user interactions, are handled by the JavaScript SDK running in the browser.

To connect both sides into a single visitor session, set up the client-side SDK with the configuration from the server.

Set up the client-side SDK

After processing a request, persist the session cookies and configure the client-side SDK, so the browser works transparently with the same visitor and client ID:

index.php
12345678
<?phpuse Croct\Plug\Croct;
$croct = Croct::fromDotenv();Croct::emitCookies();?><script src="https://cdn.croct.io/js/v1/lib/plug.js"></script><script>croct.plug(<?= json_encode($croct->getPlugOptions()) ?>);</script>

The emitCookies call writes the session cookies before any output, and getPlugOptions returns the application ID and cookie configuration that configure the client-side SDK to read those same cookies and work transparently with the same session.

Event tracking

Once the client-side SDK is configured, the JavaScript SDK tracks user interactions, such as page views, clicks, and conversions, directly from the browser.

See Event tracking for how to track events with the JavaScript SDK.

Response caching

Our framework integrations, such as the Laravel, Symfony, and Drupal SDKs, mark personalized responses as private automatically.