Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support European and other servers #36

Merged
merged 1 commit into from Sep 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/Amplitude.php
Expand Up @@ -20,6 +20,14 @@ class Amplitude
*/
protected $apiKey;

/**
* The API URL to use for all events generated by this instance
* Default will be const AMPLITUDE_API_URL
*
* @var string
*/
protected $apiUrl;

/**
* The event that will be used for the next event being tracked
*
Expand Down Expand Up @@ -118,13 +126,16 @@ public static function getInstance($instanceName = 'default')
* Constructor, optionally sets the api key
*
* @param string $apiKey
* @param \Psr\Log $logger
* @param string $apiUrl
*/
public function __construct($apiKey = null)
public function __construct($apiKey = null, $apiUrl = null)
{
if (!empty($apiKey)) {
$this->apiKey = (string)$apiKey;
}
if (!empty($apiUrl)) {
$this->apiUrl = (string)$apiUrl;
}
// Initialize logger to be null logger
$this->setLogger(new Log\NullLogger());
}
Expand All @@ -136,11 +147,13 @@ public function __construct($apiKey = null)
*
* @param string $apiKey Amplitude API key
* @param string $userId
* @param string $apiUrl Amplitude API URL
* @return \Zumba\Amplitude\Amplitude
*/
public function init($apiKey, $userId = null)
public function init($apiKey, $userId = null, $apiUrl = null)
{
$this->apiKey = (string)$apiKey;
$this->apiUrl = (string)$apiUrl;
if ($userId !== null) {
$this->setUserId($userId);
}
Expand Down Expand Up @@ -487,11 +500,12 @@ protected function sendEvent()
if (empty($this->event) || empty($this->apiKey)) {
throw new \InternalErrorException('Event or api key not set, cannot send event');
}
$ch = curl_init(static::AMPLITUDE_API_URL);
$url = empty($this->apiUrl) ? static::AMPLITUDE_API_URL : $this->apiUrl;
$ch = curl_init($url);
if (!$ch) {
// Could be a number of PHP environment problems, log a critical error
$this->logger->critical(
'Call to curl_init(' . static::AMPLITUDE_API_URL . ') failed, unable to send Amplitude event'
'Call to curl_init(' . $url . ') failed, unable to send Amplitude event'
);
return;
}
Expand Down