PHP code example of hostinger / amplitude-php

1. Go to this page and download the library: Download hostinger/amplitude-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/ */

    

hostinger / amplitude-php example snippets




$apiKey = '123';
$amplitudeClient = new Amplitude\AmplitudeClient($apiKey);

$amplitudeEvent = new Amplitude\Message\Event();

// For user properties
$amplitudeEvent
    ->set('eventType', 'test.event')
    ->set('userId', 1)
    ->set('deviceId', 1)
    ->set('city_id', 1)
    ->set('country_id', 1);

// For event properties
$amplitudeEvent
    ->addToEventProperties('revenue', 1);

try {
    $response = $amplitudeClient->track($amplitudeEvent);
    print 'event tracked';
} catch (Exception $e) {
    print $e->getMessage();
}