Personalization made Simple


Keywords
api, sdk, SuggestGrid
License
MIT

Documentation

SuggestGrid PHP Client

We will walk through how to get started with SuggestGrid PHP Client in three steps:

  1. Configuration

  2. Post actions

  3. Get recommendations

Getting Started

In this guide we will demonstrate how to display personalized recommendations on an existing PHP Framework project.

We have a movie catalog PHP Framework application, SuggestGridMovies, similar to IMDb. For logged in users we want to display movies that similar people viewed on movie pages. Let's implement this feature in five minutes with SuggestGrid!

1. Configuration

We are beginning the development by adding the client as a dependency.

SuggestGrid PHP client is available in packagist at packagist.org/packages/suggestgrid/suggestgrid.

In order to use the client with composer add the following to your composer.json file:

"require": {
    "suggestgrid/suggestgrid": "*"
}

Once you sign up for SuggestGrid, you'll see your SUGGESTGRID_URL parameter on the dashboard in the format below:

http://{user}:{pass}@{region}.suggestgrid.space/{app-uuid}

You can authenticate your application using SUGGESTGRID_URL environment variable like the example below:

$suggestGridClient = new SuggestGridLib\SuggestGridClient(getenv('SUGGESTGRID_URL'));

Every recommendation logic needs to belong to a type. For this demonstration we can create an implicit type named as views. This could be done either from the dashboard or with a snippet like this:

$type_name = 'views';
$suggestGridTypeController = $suggestGridClient->getType();

try {
    $suggestGridTypeController->getType($type_name);    
} catch (SuggestGridLib\APIException $e) {
    $suggestGridTypeController->createType($type_name);
}

2. Post actions

Once the type exists, let's start posting actions. We should invoke SuggestGrid client's SuggestGridLib\Controllers\ActionController::postAction( $action ) when an user views an item in our application.

We can do this by putting the snippet below on the relevant point:

$suggestGridActionController = $suggestGridClient->getAction();

$action = new SuggestGridLib\Models\Action($type_name, '1', '2');
$suggestGridActionController->postAction($action);

The more actions SuggestGrid gets, more relevant and diverse its responses are.

3. Get recommendations

Finally, let's show "movies similar users viewed" on movie pages.

SuggestGrid needs recommendation models for returning recommendations. Model generation is scheduled in every 24 hours. In addition, instant model generations can be triggered on the dashboard.

Once the first model generated for 'views' type, recommendations could be get using a snippet like the following:

$suggestGridRecommendationController = $suggestGridClient->getRecommendation();

$recommendedItemsResponse = $suggestGridRecommendationController->getRecommendedItems(array('type' => $type_name, 'user_id' => 1));
$recommendedItems = $recommendedItemsResponse->items;