In Ringostat, historically, we have integration with Google Analytics from the beginning. That is a requirement.
As call tracking, we need to post data about phone calls to sessions of clients, so they will count as events, decrease bounce, and can be used as goals.
With Google Universal Analytics and release of measurement protocol, this integration became much better, and the first call we registered through measurement protocol on December 29th, 2012, it was in closed beta for that moment. As I know, we were the first call tracking service to do that, but I made a big marketing mistake not to use this in communication.
But time moves forward, and Google Analytics has a new stage in beta Apps+Web, and we got a client that uses that type of account. And we discovered that our integration doesn’t work because of new collect endpoint and entirely different way events work there.
But there is still so low amount of information the only useful article I found from David Vallejo, but it’s not currently cover what mandatory fields are and how to get their values.
So in this article, I’ll share a summary of mine tries and fails. Which fields mandatory and how to fill them.
Same as previously, we need to send data to collect endpoint, but now it has another URL. Also changed the protocol version, now it’s 2. And the way how tracking ID now looks like and now it’s not tracking ID but stream ID, and you can have different streams for one property.
- Session ID, for session ID, used UNIX timestamp of session start and stored in the new cookie that has a name like _ga_XXXXXXXXX where XXXXXXXXX is stream ID without G-.
- Session count, number of sessions for this clientId. Weird thing, but it looks like this is required, but it also stored in the cookie.
To parse those variables from the cookie in one line I modified suggested snippets of code to:
Just fix XXXXXXXXX with yours stream ID.
Long story short, we need to build the request with the parameters that I found as required and still send it to https://www.google-analytics.com/g/collect. I found strange information that I have to use only POST request with separation some parameters in URL and other in payload, but GET works fine also. So the params are
|Parameter||meaning||What should we use here|
|tid||Stream ID||G-XXXXXXXXX (find in account or your code)|
|en||Event name||string, how you want to name your event ex. ‘call’|
Also, it’s good to add _dbg=1 for debugging to see data in realtime at DebugView (extremely cool feature!).
After collection such params you can build URL that would look like:
Call it, and in 10 seconds, see the event in DebugView if you have done everything right. After that, you can improve this call with additional event params and user params.