Search code examples
google-analyticsmeasurement-protocol

Google Analytics Measurement Protocol / real time events not showing


I am logging HTTP POST requests from an embedded app using C code and seeing real-time events show up for one GA Account but not for another.

In both cases, the events turn up in the App Overview the following day as registered messages so the posting appears to be working. I am not however seeing the events turn up in the Real-Time section.

Notes:

    i) The Client ID is the same GUID in both cases [cid=35009a79-1a05-49d7-b876-2b884d0f825b]
    ii) The only difference is the Tracking Code [tid=UA-XXXX-YY]
    iii) I understand the parameters "ev" and "el" are not necessary (and inserting them makes no difference)
    iv) Inserting the "an" parameter (e.g. an=MyApp) causes the event to show up in real-time; but removing the an=MyApp makes the event NOT show up as a real time event (but it does show up the following day as a registered event)


Any ideas what is going on here?

[As an aside (and although this should not cause any difference), I have enabled the GA API in the Developer Console and I am using the same DeveloperConsole-generated Client ID in both cases.]

EDITED: Here is a representative snippet of the HTTP post:-

static BYTE ServerName[] = "www.google-analytics.com";
static WORD ServerPort = 80;
static BYTE GAClientID[] = "35009a79-1a05-49d7-b876-2b884d0f825b";
static BYTE GATrackingCode[] = "UA-XXXXXXX-Y";
static ROM BYTE ContentLength[4];

strcpy(pPayloadBuffer, (ROM BYTE*)"v=1");
strcat(pPayloadBuffer, (ROM BYTE*)"&tid=");
strcat(pPayloadBuffer, (ROM BYTE*)GATrackingCode);
strcat(pPayloadBuffer, (ROM BYTE*)"&cid=");
strcat(pPayloadBuffer, (ROM BYTE*)GAClientID);

strcat(pPayloadBuffer, (ROM BYTE*)"&an=MyApp2&t=pageview&dp=Test");

strcat(pPayloadBuffer, (ROM BYTE*)"&t=event&ev=55&el=label&cd2=");

// get SNTP time and convert to struct tm
dwSNTPseconds = SNTPGetUTCSeconds();
timeNow = gmtime((const time_t*)&dwSNTPseconds);

// inspect values in tm struct
sec = timeNow->tm_sec;
min = timeNow->tm_min;
hour = timeNow->tm_hour;
day = timeNow->tm_mday;
month = timeNow->tm_mon;
year = timeNow->tm_year + 1900;

// years
uitoa(year, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// months
if (month<10) {
    strcat(pPayloadBuffer, "0");
}
uitoa(month, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// days
if (day<10) {
    strcat(pPayloadBuffer, "0");
}
uitoa(day, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// hours
if (hour<10) {
    strcat(pPayloadBuffer, "0");
}
uitoa(hour, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// minutes
if (min<10) {
    strcat(pPayloadBuffer, "0");
}
uitoa(min, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// seconds
if (sec<10) {
    strcat(pPayloadBuffer, "0");
}
uitoa(sec, sBuffer);
strcat(pPayloadBuffer, sBuffer);

// Temperature
strcat(pPayloadBuffer, (ROM BYTE*)"&cm1=");
uitoa(gTemperature, tmpString);
strcat(pPayloadBuffer, tmpString);

lenPayload = strlen(pPayloadBuffer);

// Place the application protocol data into the transmit buffer
TCPPutROMString(MySocket, (ROM BYTE*)"POST /collect HTTP/1.1\r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Host: ");
TCPPutString(MySocket, ServerName);
TCPPutROMString(MySocket, (ROM BYTE*)"\r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Content-Type: text/xml; charset=utf-8\r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Content-Length: ");
uitoa(lenPayload, (BYTE*)ContentLength);
TCPPutString(MySocket, (BYTE*)ContentLength);
TCPPutROMString(MySocket, (ROM BYTE*)"\r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Accept-Language: en-us \r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Accept-Encoding: gzip, deflate \r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"Connection: Keep-Alive \r\n\r\n");
TCPPutString(MySocket, pPayloadBuffer);

// end of line
TCPPutROMString(MySocket, (ROM BYTE*)"\r\n");
TCPPutROMString(MySocket, (ROM BYTE*)"\r\n");
// Send the packet
TCPFlush(MySocket);

Solution

  • Not a full answer I am just trying to help debugging:

    For app accounts its &t=screenview not &t=pageview

    For app accounts the following are undocumented required fields

    • an – Application name example: an=My%20Awesom%20APP
    • aid – application id example: aid=com.daimto.awesom.app
    • av – application version example: av=1.0.0
    • aiid – Application Installer ID example: aiid=come.daimto.awesom.installer