Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 1.62 KB

googleanalytics.rst

File metadata and controls

55 lines (36 loc) · 1.62 KB

Google Analytics

The Google Analytics provider sends data to Google using the Measurement Protocol.

Tracking pageviews

import analytical
from analytical.providers.googleanalytics import generate_client_id

ga = analytical.Provider('googleanalytics', 'UA-XXXXXX-Y')
ga.pageview({
    "ua": "user-agent",             # User agent
    "uip": "12.34.56.78",           # User IP address
    "dl": "https://example.com",    # URL of the pageview (required)
    "dt": "page title",             # Title of the page
})

For the complete list of parameters, see the reference.

Tracking events

import analytical

ga = analytical.Provider('googleanalytics', 'UA-XXXXXX-Y')
ga.event({
    "ua": "user-agent",
    "uip": "12.34.56.78",
    "ec": "event-category",         # Event category (required)
    "ea": "event-action",           # Event action (required)
    "el": "event-label",            # Event label (optional)
    "ev": 0,                        # Event value (optional, integer)
})

See the event parameter reference for more details.

Utility functions

.. autofunction:: analytical.providers.googleanalytics.generate_client_id