You don’t need Javascript or even a specific library.

This example uses cURL from the terminal, but you can use Requests in a Python script or anything else that can do a HTTP request.

As you can see, I use many parameters in POST data (you can also use GET):

$ curl https://www.google-analytics.com/collect \
    -d "tid=UA-xxxxxxxxxx-2" \
    -d "t=event" \ 
    -d "ec=testCategory" \ 
    -d "ea=testAction" \ 
    -d "v=1" \ 
    -d "cid=12345678" \
    -o /dev/null

Parameters

  • “tid”, your tracking id
  • “t”, the hit type
  • “ec”, the event category
  • “ea”, the event action
  • “v”, is version (and its always 1)
  • “cid”, is the client unique ID (you should create one for each of your users, if you want to track them)
  • “-o /dev/null”, I am outputing the result to /dev/null

GA screenshot

GA screenshot

References

Alternatives

It is always worth mentioning that Google Analytics is not the first nor the only analytics tools. Here are three examples that are worth noting, two of which are open source and you can deploy in your network instead of using their SaaS: