1. Go to this page and download the library: Download srkt/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/ */
srkt / amplitude-php example snippets
// Create new Amplitude client
$client = new \Srkt\Amplitude\Client('your-api-key-goes-here');
// Full data event tracking
$event = new \Srkt\Amplitude\Model\Event('user1', 'registration');
// This is not full list of data setters, please check all Event class setters
$event
->setAppVersion('1.0.0')
->setCountry('USA')
->setCity('New York')
->setRevenueData(new \Srkt\Amplitude\Model\RevenueData(10.00, 5.00, 2, 'product1', 'sell'))
->setLanguage('en')
->setDeviceId('device-id-1')
->setPlatformData(
new \Srkt\Amplitude\Model\PlatformData('Moblie', 'Android', '11.0')
)
->setEventProperties(['property' => 'value'])
->setUserProperties(new \Srkt\Amplitude\Model\UserProperties(['userProperty' => 'value']));
$client->logEvent($event); // PSR-7 Response
// Event without userId tracking
$event = new \Srkt\Amplitude\Model\Event(null, 'registration', [], null, null, 'device-id1');
$client->logEvent($event); // PSR-7 Response
$events = [
new \Srkt\Amplitude\Model\Event('user1', 'registration'),
new \Srkt\Amplitude\Model\Event('user1', 'addPhoto'),
new \Srkt\Amplitude\Model\Event('user1', 'addInfo'),
];
$client->logEvents($events); // PSR-7 Response
$client = new \Srkt\Amplitude\Client('your-api-key-goes-here');
$identity = new \Srkt\Amplitude\Model\UserIdentity(
'userId1',
new \Srkt\Amplitude\Model\UserProperties(['userProperty' => 'value'])
);
$client->identifyUser($identity); // PSR-7 Response
// Full data identity tracking
$identity = new \Srkt\Amplitude\Model\UserIdentity(
'userId1',
new \Srkt\Amplitude\Model\UserProperties(['userProperty' => 'value'])
);
// This is not full list of data setters, please check all Event class setters
$identity
->setDeviceId('device-id')
->setLanguage('en')
->setStartVersion('1.0.0')
->setPlatformData()
->setPaying('paying')
->setPlatformData(
new \Srkt\Amplitude\Model\PlatformData('Moblie', 'Android', '11.0')
);
$client->identifyUser($identity); // PSR-7 Response
$identities = [
new \Srkt\Amplitude\Model\UserIdentity('user1', new \Srkt\Amplitude\Model\UserProperties(['property' => 'value'])),
new \Srkt\Amplitude\Model\UserIdentity('user2', new \Srkt\Amplitude\Model\UserProperties(['property' => 'value'])),
new \Srkt\Amplitude\Model\UserIdentity('user3', new \Srkt\Amplitude\Model\UserProperties(['property' => 'value'])),
];
$client->identifyUsers($identities); // PSR-7 Response
$client = new \Srkt\Amplitude\Client('your-api-key-goes-here');
// Client adapter used for Guzzle versions prior to 7.0.0
$httpClient = new \Srkt\Amplitude\Http\Client\GuzzlePsr18ClientAdapter([
'timeout' => 0,
'allow_redirects' => false,
'proxy' => '192.168.16.1:10'
]);
$client->setHttpClient($httpClient);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.