GithubHelp home page GithubHelp logo

isabella232 / ga-event-tracker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silinternational/ga-event-tracker

0.0 0.0 0.0 23 KB

Lightweight wrapper in Go for sending events to Google Analytics Measurement Protocol

License: MIT License

Go 97.16% Dockerfile 2.84%

ga-event-tracker's Introduction

Google Analytics - Event Tracker

This package is a lightweight wrapper for the Google Analytics Measurement Protocol v4 specifically for Events.

We like to use GA to track various operational events/metrics like deploying apps, merging PRs, etc. So we just need a very simple way to send these events to GA. While the Measurement Protocol can handle a lot more than this package supports, we've created this as minimal as possible to keep it as simple as possible to use.

If there are additional features of MP that you'd like supported, open an issue to discuss it with us and then possibly a pull request to add the feature, although try to keep the API the same.

Usage

The SendEvent method takes two parameters, the first is a Meta struct intended to hold parameters that are not individual event related but needed for the API call. Initially it is just APISecret and UserID, though it could be extended to include other option fields like timestamp_micros, user_properties and non_personalized_ads. See https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference#payload_post_body for more info on the request body structure.

Each call to the MP API can include up to 25 events, so the second parameter is an array of Event structs. Each Event must have a Name, and can optionally contain a list of Params in form of map[string]interface{}.

package main

import (
	"github.com/silinternational/ga-event-tracker"
	"log"
)

func main() {
	err := ga.SendEvent(ga.Meta{
		APISecret: "asdf1234",
		ClientID: "abc1234",
		MeasurementID: "G-N1235ZM",
	}, []ga.Event{
		{
			Name: "custom_event",
			Params: ga.Params{
				"category": "something",
				"project":  "whatever",
			},
		},
	})

	if err != nil {
		log.Fatal(err)
	}
}

ga-event-tracker's People

Contributors

fillup avatar briskt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.