Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save predictioniogists/6908425 to your computer and use it in GitHub Desktop.
Save predictioniogists/6908425 to your computer and use it in GitHub Desktop.
<?php
// Use Composer's autoloader to load PredictionIO PHP SDK.
require_once("vendor/autoload.php");
use PredictionIO\PredictionIOClient;
// In the beginning of your application, you need to instantiate the PredictionIO client object.
// You need this client object to import data into PredictionIO and retrieve prediction results.
// Add this line to the place where you do initialization:
$client = PredictionIOClient::factory(array("appkey" => "your app key"));
// Add the following code snippets to your application logic respectively:
// When a new user registers:
$command = $client->getCommand('create_user', array('pio_uid' => "new user id"));
$response = $client->execute($command);
// When a new app registers:
$command = $client->getCommand('create_item', array('pio_iid' => "new app id", 'pio_itypes' => "app"));
$response = $client->execute($command);
// When a user logs in:
$client->identify("the logged-in user ID");
// When a logged-in user views an app:
$client->execute($client->getCommand(
'record_action_on_item',
array('pio_action' => 'view', 'pio_iid' => "the viewed app id")
));
// When a logged-in user rates an app:
// the variable $rating stores the rating value (from 1 to 5)
$client->execute($client->getCommand(
'record_action_on_item',
array('pio_action' => 'rate', 'pio_iid' => "the rated app id", 'pio_rate' => $rating)
));
// When a logged-in user pays for an app:
// Use built-in action "conversion" to represent the "pay" action
$client->execute($client->getCommand(
'record_action_on_item',
array('pio_action' => 'conversion', 'pio_iid' => "the paid app id")
));
?>
@Nathan-Srivi
Copy link

hi sir, plz tell me how to create new user register and add items, view items...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment