Last active
July 22, 2021 17:58
-
-
Save darkoromanov/bf1845fe750c9bd9b495239bf961db26 to your computer and use it in GitHub Desktop.
Freemius integration for Fomo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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