Created
March 8, 2018 12:04
-
-
Save leinardi/56c9c23d7d4cc97e818d6db2bc32da7d to your computer and use it in GitHub Desktop.
Track an Event from command line to Google Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
TID="UA-XXXX-Y" # The tracking ID / web property ID. The format is UA-XXXX-Y. All collected data is associated by this ID. | |
while getopts ":a:c:l:" opt; do | |
case $opt in | |
a) | |
ACTION="$OPTARG" | |
;; | |
c) | |
CATEGORY="$OPTARG" | |
;; | |
l) | |
LABEL="$OPTARG" | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
#echo "Action = ${ACTION}" | |
#echo "Category = ${CATEGORY}" | |
#echo "Label = ${LABEL}" | |
CID=$(uuidgen); | |
curl \ | |
--silent \ | |
--data-urlencode "v=1" \ | |
--data-urlencode "t=event" \ | |
--data-urlencode "tid=${TID}" \ | |
--data-urlencode "cid=${CID}" \ | |
--data-urlencode "ec=${CATEGORY}" \ | |
--data-urlencode "ea=${ACTION}" \ | |
--data-urlencode "el=${LABEL}" \ | |
http://www.google-analytics.com/collect > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yep, that's how you use it, you just need to change the
TID="UA-XXXX-Y"
with the one you want to use for the tracking.