Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

event is fired without error but didn't recieved in google analytics #10

Open
itaysmalia opened this issue Aug 26, 2020 · 4 comments
Open

Comments

@itaysmalia
Copy link

package main

import (
	"github.com/jpillora/go-ogle-analytics"
	"log"
	"os"
)

var client *ga.Client
var trackingID string

func initClient() {
	trackingID = os.Getenv("GA_TRACKING_ID")
	var err error
	client, err = ga.NewClient(trackingID)
	if err != nil {
		panic(err)
	}
}
func sendReport(event eventStruct) {
	statsEvent := ga.NewEvent(event.Category, event.Action)
	if event.Label != "" {
		statsEvent.Label(event.Label)
	}
	err := client.Send(statsEvent)
	if err != nil {
		panic(err)
	}
	log.Printf("event fired!!")
}

tracking id is true and there is no any error

@vladbash
Copy link

vladbash commented Sep 5, 2020

I have the same behavior, do you have any solution?

@itaysmalia
Copy link
Author

I have the same behavior, do you have any solution?

I moved to a nodejs service... the universal-analytics npm package is working well.

@zachwreed
Copy link

Found the issue if anyone feels like fixing it in the repo.

Looking at Google Analytics Measurement Protocol Reference it states that

user_agent_string – Is a formatted user agent string that is used to compute the following dimensions: browser, platform, and mobile capabilities.
If this value is not set, the data above will not be computed.

So adding a valid user agent to the POST request took care of the issue for me.

@roymoran
Copy link

Thanks @zachwreed. That explains why it won't compute the browser properties but it should still register the event regardless. But you're right once a user agent is set the event registered immediately for me. For those facing the problem set the agent with client.UserAgentOverride().

package main

import "github.com/jpillora/go-ogle-analytics"

func main() {
	client, err := ga.NewClient("UA-XXXXXXXX-Y")
        client.UserAgentOverride("your user agent string")

	if err != nil {
		panic(err)
	}

	err = client.Send(ga.NewEvent("Foo", "Bar").Label("Bazz"))
	if err != nil {
		panic(err)
	}

	println("Event fired!")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants