Getting Started
Server-Side API Endpoint

Server-Side API Endpoint

This container type enables you to easily send and receive any data model to spesicific destination using server-side enpoint and custom subdomain.

⚠️

We are currently performing maintenance on this guide.


Server-side Google Analytics 4 Measurement Protocol Endpoint Guide

Endpoint: api.usehardal/mp/gtag/:containerID

Overview

This endpoint allows you to integrate Google Analytics tracking into Hardal tool using the Measurement Protocol. It processes tracking data based on the provided containerID.

Request Type

  • Method: GET

Parameters

ParameterDescriptionRequired/Opt.
containerIDID of the container in the database.Required
client_idClient ID for tracking.Required
event_nameEvent name to be tracked.Required
timestamp_microsNumber, timestamp in microseconds.Optional
user_idString, user identifier.Optional
user_propertiesObject, additional user properties.Optional
consentObject, user consent details.Optional
non_personalized_adsBoolean, indicating non-personalized ads.Optional

Examples

Example Request

curl -X GET "https://api.usehardal.com/mp/gtag/yourContainerID?client_id=123&event_name=purchase"

Example Response

{
    "data": { "example_key": "example_value" },
    "target": "yourContainerID",
    "params": { "client_id": "123", "event_name": "purchase" }
}

Error Handling

  • If the specified containerID is not found, an error will be thrown.
  • If mandatory parameters (client_id or event_name) are missing, an error will be thrown.
  • Other errors may occur, providing detailed error messages.

Integration Steps

  1. Retrieve Container Information: Ensure the specified containerID exists.

  2. Extract Container Settings: Retrieve settings including measurement_id, api_secret, etc.

  3. Handle Queries: Extract and validate mandatory and optional queries.

  4. Construct Payload: Filter and construct a payload based on the extracted data.

  5. Send Data to Google Analytics: Use the postAnalytics function to send the payload.

  6. Return Response: Return a JSON response with data, target container ID, and processed parameters.

Additional Notes

  • Adjust the base URL according to Hardal.
  • Customize error messages and handling based on your requirements.

Feel free to adapt the provided cURL example and adjust the code to suit Hardal API's specific needs.