Google Analytics Measurement Protocol

The Google Analytics Measurement Protocol is the server-side equivalent of embedding Google Analytics into a web page.

It means that you can log any sort of activity - Raw TCP or UDP events, or specific interactions that are triggered by events like AJAX.

API Documentation

For full API documentation, visit

The API documentation explains every property that can be set within the system.


The PerfectGAMeasurementProtocol struct enables the setting of application-wide defaults for Property ID and Hit Type.

PerfectGAMeasurementProtocol.propertyid = "UA-XXXXXXXX-X"
PerfectGAMeasurementProtocol.hitType = "pageview"


Add this project as a dependency in your Package.swift file.

.Package(url: "", majorVersion: 3)

Example Usage

To set up and execute the logging of an event:

PerfectGAMeasurementProtocol.propertyid = "UA-XXXXXXXX-X"
let gaex = PerfectGAEvent()
gaex.user.uid = "donkey"
gaex.user.cid = "kong" = "aua" = "ci"
gaex.system.fl = "x" = 2

do {
    let str = try gaex.generate()
    let resp = gaex.makeRequest(useragent: "TestingAPI1.0", body: str)
} catch {

A series of common hit types and configurations can be found in Google's documentation,