🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/OzqurYalcin/google-analytics

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/OzqurYalcin/google-analytics

v0.0.0-20230220005025-ed55dad8f7a1
Source
Go
Version published
Created
Source

license documentation

Google-Analytics

An easy-to-use Google Analytics API (v1) via Measurement Protocol with golang

Installation

go get github.com/ozgur-yalcin/google-analytics

Measuring Purchases Example

package main

import (
	"net/http"
	"time"

	ga "github.com/ozgur-yalcin/google-analytics/src"
	"github.com/google/uuid"
)

func main() {
	http.HandleFunc("/", view)
	server := http.Server{Addr: ":8080", ReadTimeout: 30 * time.Second, WriteTimeout: 30 * time.Second}
	server.ListenAndServe()
}

func view(w http.ResponseWriter, r *http.Request) {
	api := new(ga.API)
	api.UserAgent = r.UserAgent()
	api.ContentType = "application/x-www-form-urlencoded"

	client := new(ga.Client)
	client.ProtocolVersion = "1"
	client.ClientID = uuid.New().String()
	client.TrackingID = "UA-xxxxxxxx-x"
	client.HitType = "pageview"
	client.DocumentLocationURL = "https://www.example.com/payment"
	client.DocumentTitle = "Payment"
	client.DocumentEncoding = "UTF-8"

	product := new(ga.Product)
	product.SKU = "P1234"
	product.Name = "product name"
	product.Brand = "product brand"
	product.Price = "1.00"
	product.Quantity = "1"
	client.Products = append(client.Products, product)
	client.ProductAction = "purchase"
	client.TransactionID = "T1234"
	client.TransactionRevenue = "1.00"
	client.CurrencyCode = "TRY"

	if r.URL.Path == "/" { // favicon blocker
		api.Send(client)
	}
}

FAQs

Package last updated on 20 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts