anatol-1988 / measurement / Measurement

This module implements Google protocol for Analytics. You can find its description on https://developers.google.com/analytics/devguides/collection/protocol/v1

Request constructors

get : Hit -> { expect : Http.Expect Msg, url : String }

Sends hit to GA using POST GET request

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

post : Hit -> { url : String, body : Http.Body, expect : Http.Expect Msg }

Sends hit to GA using POST HTTP request

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

batch : List Hit -> { url : String, body : Http.Body, expect : Http.Expect Msg }

Batching multiple hits in a single request

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


type Msg

HTTP response on hit


type alias Hit =
{ hitType : HitType
, trackingId : String
, clientId : String
, payload : List Parameter 
}

All fields that every request should contain

Helpers

event : String -> String -> String -> String -> String -> Basics.Int -> Platform.Cmd.Cmd Msg

Sends hit to GA HTTP post request with event hit. Events are user interactions with content that can be measured independently from a web-page or screen load. Downloads, link clicks, form submissions, and video plays are all examples of actions you might want to analyze as Events.

event "UA-XXXXX-Y" "555" "Category" "Action" "Label" 55

pageview : String -> String -> String -> Platform.Cmd.Cmd Msg

Sends hit to GA HTTP post request with pageview hit. A pageview is an instance of a page being loaded (or reloaded) in a browser.

pageview "UA-XXXXX-Y" "555" "/pageA"