Using the Fullstory API to Get Page Analytics in PHP

by Endgrate Team 2024-08-22 5 min read

Fullstory homepage

Introduction to Fullstory API for Page Analytics

Fullstory is a powerful analytics platform that provides comprehensive insights into user interactions on websites and applications. By capturing detailed session data, Fullstory enables businesses to understand user behavior, optimize user experience, and enhance digital products.

Developers might want to integrate with Fullstory's API to access detailed page analytics, which can be crucial for identifying user engagement patterns and improving website performance. For example, a developer could use the Fullstory API to retrieve page analytics data and analyze user interactions to optimize website layout and content strategy.

Setting Up Your Fullstory API Test Account

Before diving into the Fullstory API for page analytics, you need to set up a test account. This setup will allow you to experiment with API calls and understand how Fullstory's data can be integrated into your applications.

Create a Fullstory Account

If you don't already have a Fullstory account, you can sign up for a free trial on the Fullstory website. This trial will give you access to the necessary features to test and interact with the API.

  • Visit the Fullstory website and click on the "Start Free Trial" button.
  • Follow the on-screen instructions to create your account.
  • Once your account is created, log in to access the Fullstory dashboard.

Generate an API Key for Fullstory

To interact with the Fullstory API, you need an API key. This key will authenticate your requests and allow you to access data.

  • Navigate to the "Settings" section in your Fullstory dashboard.
  • Go to the "API Keys" section.
  • Click on "Create key" to generate a new API key.
  • Enter a meaningful name for your key and select the appropriate permission level (Admin or Architect).
  • Click "Save API Key" and make sure to copy the key value. You will not be able to view it again, so store it securely.

For more details on managing API keys, refer to the Fullstory Developer Guide.

Configure API Key Permissions

Ensure that your API key has the necessary permissions to access and modify data:

  • Admin or Architect level permissions are required for viewing or deleting data.
  • Standard keys can be used for creating, updating, and batch requests.

Verify Your Setup

With your API key ready, you can now proceed to make API calls. Ensure that your key is included in the Authorization header of your requests:

Authorization: Basic {YOUR_API_KEY}

By following these steps, you will have a fully configured test account ready to explore Fullstory's API capabilities.

Fullstory authentication documentation page.
sbb-itb-96038d7

Making API Calls to Fullstory for Page Analytics Using PHP

To retrieve page analytics from Fullstory using PHP, you'll need to make HTTP requests to the Fullstory API. This section will guide you through the process of setting up your PHP environment, making the API call, and handling the response.

Setting Up Your PHP Environment for Fullstory API

Before making API calls, ensure you have the following prerequisites:

  • PHP version 7.4 or higher installed on your machine.
  • The cURL extension enabled in your PHP configuration.

To verify that cURL is enabled, check your php.ini file or run phpinfo() in a PHP script.

Installing Required PHP Dependencies

For making HTTP requests, we'll use PHP's built-in cURL functions. Ensure that your PHP environment is configured to use these functions.

Example Code to Retrieve Fullstory Page Analytics

Create a PHP script named get_fullstory_page_analytics.php and add the following code:


<?php
// Set the API endpoint and your API key
$apiUrl = "https://api.fullstory.com/segments/v1/:id";
$apiKey = "YOUR_API_KEY";

// Initialize cURL session
$ch = curl_init($apiUrl);

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Basic " . base64_encode($apiKey),
    "Accept: application/json"
]);

// Execute the request
$response = curl_exec($ch);

// Check for errors
if (curl_errno($ch)) {
    echo 'Request Error:' . curl_error($ch);
    exit;
}

// Close cURL session
curl_close($ch);

// Decode the JSON response
$data = json_decode($response, true);

// Output the page analytics data
if (isset($data['id'])) {
    echo "Segment ID: " . $data['id'] . "\n";
    echo "Segment Name: " . $data['name'] . "\n";
    echo "Created By: " . $data['creator'] . "\n";
    echo "Created On: " . $data['created'] . "\n";
    echo "Segment URL: " . $data['url'] . "\n";
} else {
    echo "Failed to retrieve page analytics data.";
}
?>

Replace YOUR_API_KEY with the API key you generated earlier. This script initializes a cURL session, sets the necessary headers, and executes a GET request to the Fullstory API endpoint.

Understanding the API Response

The API response will contain details about the segment, such as its ID, name, creator, creation date, and URL. You can use this information to analyze user interactions on your website.

Handling Errors and Verifying API Call Success

To ensure your API call was successful, check the response for the expected data fields. If the response contains an error, handle it gracefully by logging the error message and taking appropriate action.

For more details on error codes and handling, refer to the Fullstory API documentation.

Fullstory API call documentation page.

Conclusion and Best Practices for Using Fullstory API in PHP

Integrating with the Fullstory API to retrieve page analytics in PHP can significantly enhance your ability to analyze user interactions and optimize your website's performance. By following the steps outlined in this guide, you can efficiently set up your environment, authenticate your requests, and handle API responses.

Best Practices for Secure and Efficient Fullstory API Integration

  • Secure API Key Storage: Always store your API keys securely. Consider using environment variables or a secure vault to prevent unauthorized access.
  • Handle Rate Limiting: Be mindful of API rate limits to avoid throttling. Implement retry logic with exponential backoff to manage rate limit errors gracefully.
  • Data Transformation: Standardize and transform data fields as needed to ensure consistency across your application.
  • Error Handling: Implement robust error handling to manage API call failures. Log errors for further analysis and user notification.

Enhance Your Integration Strategy with Endgrate

While integrating with Fullstory's API provides valuable insights, managing multiple integrations can be complex and time-consuming. Endgrate simplifies this process by offering a unified API endpoint that connects to various platforms, including Fullstory.

By leveraging Endgrate, you can streamline your integration efforts, reduce development time, and focus on your core product. Explore how Endgrate can enhance your integration strategy by visiting Endgrate today.

Read More

Ready to get started?

Book a demo now

Book Demo