getVariantId
Learn how to read the ID of the served variant.
This method gives you the ID of the variant served to the visitor.
Signature
This method has the following signature:
public function getVariantId(): stringThis method returns the ID of the variant served to the visitor.
Example
Here is a basic example of how to use this method:
<?phpuse Croct\Plug\Croct;use Croct\Plug\FetchOptions;
$croct = Croct::fromDotenv();$options = FetchOptions::defaults()->withSchema();$experiment = $croct->fetchContent('home-banner', $options)->getMetadata()->getExperience()->getExperiment();$variantId = $experiment->getVariantId();