Siren

Opportunities

Accessing and querying Siren opportunity records through the PHP data layer.

Last updated: October 26, 2026

An opportunity in Siren is an ephemeral tracking record created automatically when a visitor clicks an affiliate link or otherwise triggers an attribution-worthy interaction. Opportunities represent the earliest stage of the attribution pipeline. A potential customer touchpoint may eventually lead to an engagement, conversion, and transaction.

Siren’s customer records gather a shopper’s opportunities. That page also covers the REST fields that link an opportunity’s customer to collaborators.

You will almost never create opportunities manually. They are produced by Siren’s trigger strategies in response to site visits, cookie lookups, and other detection mechanisms. The opportunity system handles creation, deduplication, merging, and invalidation through the normal event flow. The primary reason to access the opportunity datastore directly is reading opportunity data for reporting, looking up an opportunity to inspect its status, or tracing the attribution chain backward from a conversion.

Siren is built on an event-driven architecture. Opportunities are created and managed by trigger strategies that respond to visitor activity events. If you need to support a new type of visitor interaction, register a custom trigger strategy rather than creating opportunity records directly. This ensures the full event pipeline fires and downstream systems (engagements, conversions) respond correctly.

Accessing opportunity data

The opportunity datastore is available through dependency injection or the static facade. Dependency injection is preferred for extension code wired through an initializer. The facade is convenient for standalone scripts, theme files, or other code running outside Siren’s container.

use Siren\Opportunities\Core\Datastores\Opportunity\Interfaces\OpportunityDatastore;
use Siren\Opportunities\Core\Models\Opportunity;

class AttributionTracer
{
    protected OpportunityDatastore $opportunities;

    public function __construct(OpportunityDatastore $opportunities)
    {
        $this->opportunities = $opportunities;
    }

    public function getActiveOpportunities(): array
    {
        return $this->opportunities->andWhere([
            ['column' => 'status', 'operator' => '=', 'value' => 'active']
        ]);
    }

    public function getOpportunity(int $id): Opportunity
    {
        return $this->opportunities->find($id);
    }
}
use Siren\Opportunities\Core\Facades\Opportunities;

$active = Opportunities::andWhere([
    ['column' => 'status', 'operator' => '=', 'value' => 'active']
]);

The Opportunities facade has no single-record lookup. To fetch one opportunity by ID, inject OpportunityDatastore and call find(), as the dependency injection tab shows.

The opportunity model

Each opportunity record is represented by an Opportunity model instance.

FieldTypeDescription
idintPrimary key
statusstringactive, inactive, invalid, or erased. An erased opportunity belongs to a shopper whose data was erased, and a cookie or header that names it finds nothing
lastTriggeredDateTimeWhen the opportunity was most recently triggered
createdDateDateTimeWhen the opportunity was first recorded
modifiedDateDateTimeWhen the record was last updated

Getter methods: getStatus(), getLastTriggered(), getCreatedDate(), getModifiedDate().

The opportunity model is deliberately lightweight. It does not carry collaborator or program information. Those associations are established by engagements, which link an opportunity to a collaborator within a program. A single opportunity can have multiple engagements across different programs if the visitor’s interaction triggers attribution in more than one context.

The lastTriggered timestamp updates each time the visitor re-triggers the opportunity (for example, a return visit through the same affiliate link). This allows Siren to track recency without creating duplicate records.

Available methods

This datastore supports the shared methods documented in the introduction and adds no domain-specific ones.

Tracing a conversion back to its opportunity

A conversion doesn’t store its opportunity. It stores the engagement that won it, and the engagement stores the opportunity. To trace the attribution chain backward, follow those two links with find(). Each find() throws RecordNotFoundException when the record is missing.

use PHPNomad\Datastore\Exceptions\RecordNotFoundException;
use Siren\Conversions\Core\Datastores\Conversion\Interfaces\ConversionDatastore;
use Siren\Engagements\Core\Datastores\Engagement\Interfaces\EngagementDatastore;
use Siren\Opportunities\Core\Datastores\Opportunity\Interfaces\OpportunityDatastore;

class ConversionTracer
{
    protected ConversionDatastore $conversions;
    protected EngagementDatastore $engagements;
    protected OpportunityDatastore $opportunities;

    public function __construct(
        ConversionDatastore $conversions,
        EngagementDatastore $engagements,
        OpportunityDatastore $opportunities
    ) {
        $this->conversions = $conversions;
        $this->engagements = $engagements;
        $this->opportunities = $opportunities;
    }

    public function traceConversion(int $conversionId): ?array
    {
        try {
            $conversion = $this->conversions->find($conversionId);
            $engagement = $this->engagements->find($conversion->getEngagementId());
            $opportunity = $this->opportunities->find($engagement->getOpportunityId());

            return [
                'opportunityId' => $opportunity->getId(),
                'status' => $opportunity->getStatus(),
                'firstSeen' => $opportunity->getCreatedDate(),
                'lastTriggered' => $opportunity->getLastTriggered(),
            ];
        } catch (RecordNotFoundException $e) {
            return null;
        }
    }
}

Your privacy choices

Account, checkout and chat you request work without optional tracking. Choose whether to allow these other uses on this website.

You can change or withdraw your choices at any time using “Privacy choices.” We remember your choice for 180 days. Read our privacy policy.