getPlugOptions

Learn how to get the options to set up the client-side SDK.

This method provides the options needed to set up the JavaScript SDK in the browser, such as the application ID and cookie configuration.

These options configure the client-side SDK to work transparently with the same visitor session started on the server. For more information, see Client-side setup.

Signature

This method has the following signature:

public function getPlugOptions(): array

This method returns an array of options used to configure the client-side SDK.

Example

Here is a basic example of how to use this method:

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>