Analytics - ENOTCONN


#1

Please excuse my ignorance - about Google Analytics, web APIs generally, etc etc etc.

I’m using the Analytics Collection demo project.
I’ve built in both debug and release modes.
I’ve inserted my Google Analytics API key.
My internet connection is stable.

I have found the folder where unsent events would be saved. There is nothing there which suggests to me the connection was made successfully.

But there’s nothing I can see in Google Analytics that looks anything like a button press event log. And whenever an event should be sent I consistently get errors of the type:

AnalyticsCollection[67957:1179079] TIC Read Status [3:0x0]: 1:57

Which I understand is a TCP ENOTCONN (not connected error).

Please help! Any advice on what I should expect would help me feel less crazy. Thank you :slight_smile:


#2

What OS are you running your app on? Do you have the correct permissions to connect to an external server?

Also GA has a considerable lag - you can see live events coming in on some of the screens but you won’t be able to query the collected data for something like 12 hours.


#3

Thanks t0m, I’m on High Sierra 10.13.3. I’m also not sure about external server connection permissions (unsure how to check for that despite a respectable amount of Googling), but I have used web APIs successfully in tutorial apps that I’ve built on this machine before (admittedly on previous OSX versions, but with no special configuration from me).

Not sure if that’s too much info? Thanks!


#4

There shouldn’t be anything stopping outbound network requests on MacOS unless there’s some kind of firewall configured.

One thing you could try is making requests to Google Analytics’ debug endpoint:

https://developers.google.com/analytics/devguides/collection/protocol/v1/validating-hits

The responses from this should give us a bit more info. Can you successfully collect analytics from requests sent by other methods (curl from the command line, for example)?


#5

Thanks again. I’ll try to work through all your suggestions tomorrow.

Meanwhile, I tried validating hits with GA’s Hit Builder (https://ga-dev-tools.appspot.com/hit-builder/).

I looked in the example project’s GoogleAnalyticsDestination class and logged the string passed by

postData.add (appData + eventData.joinIntoString ("&"));

Using my tracking ID, I found this was

v=1&tid=UA-113596049-1&t=event&ec=info&ea=appStarted&cid=AnonUser1234

When I pasted that into Hit Builder, I noticed that it reformatted the string slightly into

v=1&t=event&tid=UA-113596049-1&cid=AnonUser1234&ec=info&ea=appStarted

And the hit validated fine.

So I took that reformatted string back into the demo code and pasted it as the argument to postData.add().

The result was that I stopped getting an ENOTCONN on the following connection line

const auto success = webStream->connect (nullptr);

But this only happened when I stepped through the code. Running the code (not debugging), the errors turned up with both formats.

I guess I’ve now sent some valid startup hits, although I still can’t see them in GA. Maybe this is because it takes a while for them to come through, as you said. Or maybe it’s because my GA page is for an iOS product, whereas I should have made it for a (general) measurement protocol product. Will try to suss that too. Cheers!


#6

Curl works, with the hit formatted both ways:

My-MacBook-Pro:~ username$ curl "https://www.google-analytics.com/debug/collect?v=1&tid=UA-113596049-1&t=event&ec=info&ea=appStarted&cid=AnonUser1234"
{
  "hitParsingResult": [ {
    "valid": true,
    "parserMessage": [ ],
    "hit": "/debug/collect?v=1\u0026tid=UA-113596049-1\u0026t=event\u0026ec=info\u0026ea=appStarted\u0026cid=AnonUser1234"
  } ],
  "parserMessage": [ {
    "messageType": "INFO",
    "description": "Found 1 hit in the request."
  } ]
}
My-MacBook-Pro:~ username$ curl "https://www.google-analytics.com/debug/collect?v=1&t=event&tid=UA-113596049-1&cid=AnonUser1234&ec=info&ea=appStarted"
{
  "hitParsingResult": [ {
    "valid": true,
    "parserMessage": [ ],
    "hit": "/debug/collect?v=1\u0026t=event\u0026tid=UA-113596049-1\u0026cid=AnonUser1234\u0026ec=info\u0026ea=appStarted"
  } ],
  "parserMessage": [ {
    "messageType": "INFO",
    "description": "Found 1 hit in the request."
  } ]
}

#7

I think that probably addresses all of your suggestions - please let me know if I’ve missed anything :slight_smile:


#8

Well the next thing to try is to use the debug URL in JUCE and parse the response to see if it’s the same.


#9

Right. The debug endpoint is showing valid hits from JUCE.

It looks as if this comes down to (1) me not understanding GA and how complicated it is to set up to show your raw hit data helpfully, (2) the confusion added by the ENOTCONN errors (which still can’t explain) and the mountains of inexplicable information coming into GA (according to which my app has users in California, NY, Florida and Alaska, which is impossible).

Thanks for your help, Tom


#10

Well this forum is public - it’s possible some mischievous folks (or a bot) have taken your API key and have sent you some events…


#11

True but that was well before I posted on here. Mysterious.