App + Web Measurement ID and the /collect Endpoint - google-analytics

TL;DR: How does the Measurement ID in the new App + Web Tracking feature work with the /collect endpoint?
We use the Google Analytics Measurement Protocol to send app events to our customers' Google Analytics instances. An anonymized example of a URL we'd make a GET request to is below:
https://google-analytics.com/collect?v=1&tid=UA-TEST&ds=app&an=BRANCH-APP&t=event&ec=BranchEvent&cid=&cn=Test&cs=test&cm=test&ck=&cc=&ea=INSTALL&uip=1.2.3.4&ua=Mozilla%2F5.0%20%28Linux%3B%2028%3B%20Dalvik%2F2.1.0+%28Linux%3B+U%3B+Android+9%3B+moto+g%287%29+play+Build%2FPPYS29.105-134-9%29%20Build%2FIMM76B%29%20AppleWebKit%2F535.19%20%28KHTML%2C%20like%20Gecko%29%20Chrome%2F8.0.1025.133%20Mobile%20Safari%2F535.19%20%5BBranch%20Webhook%5D&z=1584644783123
I'm trying to figure out how this works with the new App + Web tracking feature GA recently announced. According to their implementation guide, this uses a Measurement ID which replaces the Tracking ID:
Tracking ID: UA-XXXXXX-YY
Measurement ID: G-XXXXXXXXXX
We can't find any documentation on what should change with how we're hitting the /collect endpoint for customers using App + Web Tracking. Does it replace the Tracking ID in the call? Do we make a different call entirely? Does the call stay the same and continue to work?
Any help is much appreciated!
Docs Referenced Above:
App + Web Tracking: https://www.blog.google/products/marketingplatform/analytics/new-way-unify-app-and-website-measurement-google-analytics/
Implementation: https://developers.google.com/analytics/devguides/collection/app-web/tag-guide

You are using using measurement protocol v1 (see parameter v=1), however App+Web uses a new version of the measurement protocol, version 2, that for the moment it has not yet been documented.

I faced such issues. There are not only changes between Tracking ID and Measurement ID but also there is a question about how to get a Client ID and new parameter as a Session ID, also there is another endpoint for collect, there is "/g" added in url.
I found that the necessary parameters are: v, tid, cid, sid, sct, dl, and sure en.
Details on what are those parameters are and how to get them: https://lunaxod.com/measurement-protocol-v2-google-analytics-appsweb/

Related

Unable to get companies for LinkedIn API version V2

I use the Zoonman LinkedIn API PHP SDK to get information about companies an authenticated user is an admin of, using this bit of code:
$profileCompany = $client->get(
'companies',
['is-company-admin' => "true"]
);
This worked perfectly with API version V1. However, with V2, it gives a 400 not found error. I came across this: Organization Lookup API but not exactly sure if this is the right endpoint, as there is no API call to exactly do what the above code snippet does.
Could someone please help with the right endpoint?
If you have the access token from the user this is possible in v2 of the LinkedIn API. See:
https://developer.linkedin.com/docs/guide/v2/organizations/organization-lookup-api#acls
The full URL for the basic request would be:
https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee&role=ADMINISTRATOR&state=APPROVED&projection=(*,elements*(*,organizationalTarget~(*)))
With paging:
https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee&role=ADMINISTRATOR&state=APPROVED&projection=(*,elements*(*,organizationalTarget~(*)))&start=[...]&count=[...]
And you probably want the organization logo urls as well:
https://api.linkedin.com/v2/organizationalEntityAcls?q=roleAssignee&role=ADMINISTRATOR&state=APPROVED&projection=(*,elements*(*,organizationalTarget~(*,logoV2(original~:playableStreams,cropped~:playableStreams,cropInfo))))&start=[...]&count=[...]
For linkedin-api-php-client see also:
https://github.com/zoonman/linkedin-api-php-client/issues/31
From the docs
Please note the following changes when migrating your app from v1 of
the LinkedIn API Platform:
Company Pages and Showcase Pages are now
surfaced as Organization and Brand resources, respectively. Both
resources are considered "Organizational Entities," and share common
fields and similarities in how data is accessed.
URNs uniquely
identify organizational entities, and can be generated with existing
company or showcase ids:
Organization: urn:li:organization:{company id}
The above code make call the rest api "List all companies that the member is an administrator of". It does not seems have a direct equivalent API available in v2.
Organisation lookup/search APIs seems nearest alternative.
Hope this helps.

Microsoft Health API: Getting Account Creation Date

I'm trying to load data from the Cloud API, but I don't know when to start my requests from. In the Device API there is "createdDate" key, but its never populated.
Is there a way to find this information from the API without asking the user?
I'm seeing the "createdTime" displaying correctly in my profile when I query the Profile API.
Request:
GET https://api.microsofthealth.net/v1/me/Profile
Response:
{
"firstName":"John",
"lastName":"",
"birthdate":"",
"postalCode":"",
"gender":"Male",
"height":19055,
"weight":549575,
"preferredLocale":"en-US",
"lastUpdateTime":"2016-06-04T00:07:58.950+00:00",
"createdTime":"2015-10-09T18:26:53.498+00:00"
}

Display 'Pure HTML Dashboards' or 'Custom Components' using Analytics Api

I need to display 'Pure HTML Dashboards' or 'Custom Components' as depicted in the following link https://ga-dev-tools.appspot.com/demos/embed-api/
I have google analytics account & it shows me the real time statistics perfectly for my website, but i need to display the same using the api as shown in the following link:
https://github.com/googleanalytics/embed-api-demos/blob/master/site/3-custom-components.html
I have replaced my client id in the following code:
gapi.analytics.auth.authorize({
container: 'auth',
clientid: '623325626209-j1jm9d78ge0v4uf8b9cor31qsirungrq.apps.googleusercontent.com',
});
I also updated the end date to current date as follows:
query: {
'metrics': 'ga:sessions',
'dimensions': 'ga:date',
'start-date': '30daysAgo',
'end-date': '2014-09-05'
},
So when i run the code it shows a button "Access Google Analytics", when i click on it i get the following error:
That’s an error.
Error: origin_mismatch
Application: Project Default Service Account
You can email the developer of this application at: fz1990#gmail.com
Request Details
=
scope=https://www.googleapis.com/auth/analytics.readonly https://www.googleapis.com/auth/userinfo.email
response_type=code token id_token gsession
redirect_uri=postmessage
cookie_policy=single_host_origin
proxy=oauth2relay591552393
state=524099008|0.3938720987
origin=http://localhost:27363
include_granted_scopes=true
client_id=656169223314-dbc8l4c7ro20hn8vcqqtd9rhd0e6arcb.apps.googleuserconte
Can somebody plss help me to fix this issue?
Thanx in advance
Origin mismatch is normally caused by the Javascript origins not being set correctly in the API project console. You need to make sure that the Javascript origins match the domain from which your requests are coming and to which you are returning the user after sign in.
In your case you are still using the client_id from the tutorial you need to create your own. More details can be found in the developer documentation for the embeded API in the "Create a client ID and client secret" section.
Basilcy you need to go to Google Developer console and register your application. The link above to the documentation will walk you though creating that. Hint: don't for get to add a product name and email address.
At this time the Real-time API is still in beta you will need to apply for access to it. Real time reporting api private beta fill out that form you wont hear anything from Google just wait 24 hours and give it a try it normally works by then.

Unviersal analytics - Measurement protocol

When i look at website data under "audience overview" page , I notice the System section which contains - browser , operating system and service provider.
how to set information for this using measurement protocol , any example or parameter reference for it.
It's sent in the user agent string. There's no public API to override it
You can specify User Agent Override parameters from the API in Measurement Protocol.
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#ua
Be aware this is subject to change by Google. However, at this time User Agent string CAN be overridden using the public API.

Why Google Analytics doesn't track all my events with _setcustomvar?

I'm using the following code
_gaq.push(['_setCustomVar',1,'logged-in','administrator',1],['_trackPageview']);
to track logged-in user levels on my site (running WordPress).
Now my problem is that in the last month I had around 100 new registrations, but Google Analytics only shows me 65 registered users active on my site.
Is this an error in interpreting the results or am I doing something wrong?
PREAMBLE
With Google Analytics(GA), it's impossible to get ALL your hits registred. This is not a GA specific problem. Any analytics tool can be affected.
Imagine for instance, that the user gets its connection broken while registring on your WP site. Chances are that the javascript code won't be executed. The new user will be registred hopefully, but GA won't be notified.
WORKAROUND
This workaround would be to tied the notification of GA with your registration process right on the server side:
Step 1: Register a php function with the user_register hook.
add_action('user_register', 'myplugin_registration_save');
function myplugin_registration_save($user_id) {
// GA will be notified here ...
}
Step 2: Inside this registred function notify GA of the new user registration.
Here comes php-ga. It's a GA client written in PHP. You can implement nearly every parameter and tracking feature of the original GA Javascript client. Call it to track your GA custom vars.
Here is a sample code from the php-ga site:
use UnitedPrototype\GoogleAnalytics;
// Initilize GA Tracker
$tracker = new GoogleAnalytics\Tracker('UA-12345678-9', 'example.com');
// Assemble Visitor information
// (could also get unserialized from database)
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress($_SERVER['REMOTE_ADDR']);
$visitor->setUserAgent($_SERVER['HTTP_USER_AGENT']);
$visitor->setScreenResolution('1024x768');
// Assemble Session information
// (could also get unserialized from PHP session)
$session = new GoogleAnalytics\Session();
// Assemble Page information
$page = new GoogleAnalytics\Page('/page.html');
$page->setTitle('My Page');
// Track page view
$tracker->trackPageview($page, $session, $visitor);
THERE IS MORE
Even if you implement the workaround, it may not be able to notify GA sucessfully. If GA server experiment some heavy load for instance, your notification may be lost.
I would advice you to use both system notification : GA Javascript client AND GA PHP client.
Assign them two distinct events 'JS-new-user-registred' and 'PHP-new-user-registred'. With two registred events you improve the quality of your analytic data. You improve the new registrations notification rate too.
Always keep in mind that this approach may not be 100% accurate. For example, on the client side the ga.js file may be blocked (firewall etc). At the same time, your PHP client may not be able to notify succesfully GA. It results that the new registration is not tracked.

Resources