PHP code example of ominity / ominity-api-php

1. Go to this page and download the library: Download ominity/ominity-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ominity / ominity-api-php example snippets


$ominity = new \Ominity\Api\OminityApiClient();
$ominity->setApiEndpoint("https://ominity.example.com/api");
$ominity->setApiKey("q48fd94qs98fd4sqf89fza9sqd89f4");

$result = $ominity->tracking->events->track([
    'event' => 'page_view',
    'timestamp' => gmdate(DATE_ATOM),
    'visitorId' => '648cd59e-8f79-40a7-a4de-1fb65b42c00c',
    'url' => 'https://shop.example.com/products/lounge-chair',
    'metadata' => [
        'origin_resource' => [
            'resource' => 'page',
            'id' => 42,
            'slug' => 'lounge-chair',
        ],
    ],
]);

$visitorId = $result->visitorId;

$ominity
    ->addRequestHeaders([
        'X-Forwarded-For' => '203.0.113.10',
        'X-Real-IP' => '203.0.113.10',
        'X-Ominity-Client-IP' => '203.0.113.10',
        'User-Agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
    ])
    ->tracking->events->track([
        'event' => 'page_view',
        'timestamp' => gmdate(DATE_ATOM),
    ]);

/** @var $ominity \Ominity\Api\OminityApiClient */
$ominity->enableDebugging();

try {
    $ominity->commerce->products->get(1);
} catch (\Ominity\Api\Exceptions\ApiException $exception) {
    $request = $exception->getRequest();
}

/** @var $ominity \Ominity\Api\OminityApiClient */
$ominity->disableDebugging();
bash
composer