Skip to content

Instantly share code, notes, and snippets.

@darkoromanov
Last active July 22, 2021 17:58
Show Gist options
  • Save darkoromanov/bf1845fe750c9bd9b495239bf961db26 to your computer and use it in GitHub Desktop.
Save darkoromanov/bf1845fe750c9bd9b495239bf961db26 to your computer and use it in GitHub Desktop.
Freemius integration for Fomo
<?php
// Fomo documentation: https://docs.fomo.com/reference
// Freemius documentation: http://freemius.com/help/documentation/marketing-automation/events-webhooks/
// Install Fomo PHP SDK https://github.com/usefomo/fomo-php-sdk
include "vendor/autoload.php";
define("FOMO_AUTH_TOKEN", "*********");
define("FOMO_EVENT_TYPE_ID", "123456789")
use Fomo\FomoClient;
use Fomo\FomoEventBasic;
// Get payload from the request
$body = file_get_contents('php://input');
// Convert the payload to an assoc array
$data = json_decode($body, true);
// Get the user's name
$name = ucfirst($data["objects"]["user"]["first"]) . " " . strtoupper(substr($data["objects"]["user"]["last"], 0, 1)) . ".";
// Instantiate Fomo client
$client = new FomoClient(FOMO_AUTH_TOKEN);
// Instantiate a new Fomo basic event
$event = new FomoEventBasic();
// Handle Freemius events
if($data["type"] == "subscription.created")
{
// Uncomment to save payload to file to inspect it
// file_put_contents("logs/" . $data["id"] . ".json", $body);
// Read the event_type_id from Fomo settings
$event->event_type_id = FOMO_EVENT_TYPE_ID;
$event->title = "New purchase";
$event->first_name = $name;
$event->email_address = $data["objects"]["user"]["email"];
$event->ip_address = $data["objects"]["user"]["ip"];
// Add your custom fields
$event->addCustomEventField('license', 'Ultimate');
$client->createEvent($event);
}
// Handle any other Freemius event like install.trial.started
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment