PHP code example of moesif / moesifapi-php
1. Go to this page and download the library: Download moesif/moesifapi-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/ */
moesif / moesifapi-php example snippets
use Moesif\Sender\MoesifApi;
$client = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
use Moesif\Sender\MoesifApi;
$reqdate = new DateTime();
$rspdate = new DateTime();
$event= array(
"request" => array(
"time" => $reqdate->format(DateTime::ISO8601),
"uri" => "https://api.acmeinc.com/items/reviews/",
"verb" => "PATCH",
"api_version" => "1.1.0",
"ip_address" => "61.48.220.123",
"headers" => array(
"Host" => "api.acmeinc.com",
"Accept" => "_/_",
"Connection" => "Keep-Alive",
"User-Agent" => "moesifapi-php/1.1.0",
"Content-Type" => "application/json",
"Content-Length" => "126",
"Accept-Encoding" => "gzip"),
"body" => array(
"review_id" => 132232,
"item_id" => "ewdcpoijc0",
"liked" => false
)
),
"response" => array(
"time" => $rspdate->format(DateTime::ISO8601),
"status" => 500,
"headers" => array(
"Date" => "Tue, 12 June 2020 23:46:49 GMT",
"Vary" => "Accept-Encoding",
"Pragma" => "no-cache",
"Expires" => "-1",
"Content-Type" => "application/json; charset=utf-8",
"X-Powered-By" => "ARR/3.0",
"Cache-Control" => "no-cache",
"Arr-Disable-Session-Affinity" => "true"),
"body" => array(
"item_id" => "13221",
"title" => "Red Brown Chair",
"description" => "Red brown chair for sale",
"price" => 22.23
)
),
"metadata" => array(
"foo" => "bar"
),
"user_id" => "12345",
"company_id" => "67890",
"session_token" => "23jdf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ngs98y18cx98q3yhwmnhcfx43f"
);
$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->createEvent($event);
use Moesif\Sender\MoesifApi;
// Only userId is ou want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#users for campaign schema
// metadata can be any custom object
$user = array(
"user_id" => "12345",
"company_id" => "67890", // If set, associate user with a company object
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"email" => "[email protected] ",
"first_name" => "John",
"last_name" => "Doe",
"title" => "Software Engineer",
"sales_info" => array(
"stage" => "Customer",
"lifetime_value" => 24000,
"account_owner" => "[email protected] "
)
)
);
$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUser($user);
use Moesif\Sender\MoesifApi;
$userA = array(
"user_id" => "12345",
"company_id" => "67890", // If set, associate user with a company object
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"email" => "[email protected] ",
"first_name" => "John",
"last_name" => "Doe",
"title" => "Software Engineer",
"sales_info" => array(
"stage" => "Customer",
"lifetime_value" => 24000,
"account_owner" => "[email protected] "
)
)
);
$userB = array(
"user_id" => "1234",
"company_id" => "6789", // If set, associate user with a company object
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"email" => "[email protected] ",
"first_name" => "John",
"last_name" => "Doe",
"title" => "Software Engineer",
"sales_info" => array(
"stage" => "Customer",
"lifetime_value" => 24000,
"account_owner" => "[email protected] "
)
)
);
$users = array($userA, $userB);
$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateUsersBatch($users);
use Moesif\Sender\MoesifApi;
// Only companyId is want to track ROI of acquisition channels
// See https://www.moesif.com/docs/api#update-a-company for campaign schema
// metadata can be any custom object
$company = array(
"company_id" => "67890",
"company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"org_name" => "Acme, Inc",
"plan_name" => "Free",
"deal_stage" => "Lead",
"mrr" => 24000,
"demographics" => array(
"alexa_ranking" => 500000,
"employee_count" => 47
)
)
);
$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompany($company);
use Moesif\Sender\MoesifApi;
$companyA = array(
"company_id" => "67890",
"company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"org_name" => "Acme, Inc",
"plan_name" => "Free",
"deal_stage" => "Lead",
"mrr" => 24000,
"demographics" => array(
"alexa_ranking" => 500000,
"employee_count" => 47
)
)
);
$companyB = array(
"company_id" => "6789",
"company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info
"campaign" => array(
"utm_source" => "google",
"utm_medium" => "cpc",
"utm_campaign" => "adwords",
"utm_term" => "api+tooling",
"utm_content" => "landing"
),
"metadata" => array(
"org_name" => "Acme, Inc",
"plan_name" => "Free",
"deal_stage" => "Lead",
"mrr" => 24000,
"demographics" => array(
"alexa_ranking" => 500000,
"employee_count" => 47
)
)
);
$companies = array($companyA, $companyB);
$apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
$apiClient->updateCompaniesBatch($companies);
shell
composer