anatol-1988/measurement/1.0.0

NOTE: the latest version is 2.0.0

Renamed to rielas/measurement. It is published under that name, and new versions come out there.

Versions published as anatol-1988/measurement still install under that name. 1 version of 4 come from the new location (see their notes). 3 versions could not be recovered and cannot be installed.

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/rielas/measurement.

What we checked: The repo moved to github.com/rielas/measurement. Rebuilt with git archive from commit 0490ebb1b4a8 of https://github.com/rielas/measurement (zip prefix anatol-1988-measurement-0490ebb/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 c80e27b7d4a93c815a94212e8e83828475b9ffee.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/anatol-1988/measurement/zipball/1.0.0/

Measurement Protocol

This package helps you to work with Google Analytics Measurement protocol.

Sending Required Values

POST request

Let's send page view event to the Google Analytics:

import Measurement as GA
import Parameter
import Http

GA.post
    { hitType = HitType.Pageview
    , trackingId = "UA-123456-1"
    , clientId = "555"
    , payload = [ Parameter.DocumentPath "/pageA" ]
    }
    |> Http.post

This will construct Measurement Protocol hit and send it to the POST /collect endpoint. You can check your request with Hit Builder.

GET request

For environments where you can not send POST data, you can also send HTTP GET requests.

import Measurement as GA
import Parameter
import Http

GA.get
    { hitType = HitType.Event
    , trackingId = "UA-XXXXX-Y"
    , clientId = "555"
    , payload =
        [ Parameter.CacheBuster "289372387623"
        , Parameter.EventCategory "video"
        , Parameter.EventAction "play"
        , Parameter.EventLabel "holiday"
        , Parameter.EventValue 300
        ]
    }
    |> Http.get

Batch requests

To send multiple hits in a single request, use batch mode.

import Measurement as GA
import Parameter
import Http

GA.batch
    [ { hitType = HitType.Event
      , trackingId = "UA-XXXXX-Y"
      , clientId = "555"
      , payload =
            [ Parameter.CacheBuster "289372387623"
            , Parameter.EventCategory "video"
            , Parameter.EventAction "play"
            , Parameter.EventLabel "holiday"
            , Parameter.EventValue 300
            ]
      }
    , { hitType = HitType.Pageview
      , trackingId = "UA-123456-1"
      , clientId = "5555"
      , payload = [ Parameter.DocumentPath "/pageA" ]
      }
    ]
    |> Http.post