Google Analytics Query Custom Channel Grouping - google-analytics

I am trying to pull a Custom Channel Grouping for Transaction IDs from Google Analytics. The marketing group has defined a couple of custom Channel Groupings in GA and they want me to pull these fields. I can not find any documentation anywhere which discusses this. It's not a custom dimension and it's not a custom variable. Has anyone else had to do this? Is it possible or do I have to re-implement the rules outside of GA?

Short answer: this is not currently possible (as of June 2015) in the Google Analytics API.
The best workaround I have found is to rebuild the channel grouping in the logic of the API query. For example, if you have a channel group that is defined in your custom grouping as "campaign contains shopping AND source == google," you can write that into the filters line of the optArgs call to the API.
This doesn't strike me as a sustainable, maintainable practice, however -- if the custom grouping is changed, you need to go back and change your code separately -- but it's the best solution available at the moment.

Example code is Javascript:
The filter doesn't seem to work for ga:channelGrouping, so 'filters':'ga:channelGrouping=Direct', fails with the error:
{
"error": {
"errors": [{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}],
"code": 400,
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}
}
But you can get the ga:channelGrouping back as a dimension:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': 'yesterday',
'end-date': 'today',
'dimensions':'ga:channelGrouping,ga:date, ga:landingPagePath, ga:pagePath',
'metrics': 'ga:entrances',
'sort': '-ga:date',
})
so you get it in the data:
[
/*Channel grouping*/
"(Other)",
"20150730",
"blah",
"vlah",
"7"
]
At the moment I'm planning on filtering the channel grouping in my own code once I get the result back rather than trying to get Google to do this for me. Basically because Google doesn't seem to support this right now...

Related

GA4 dimensions like language is (not set) for events sent by the measurment protocol

I am using GA4 measurement protocol to record offline conversions to Google Analytics. I have two conversion events: sale and purchase.
Events are being recorded and in the Monetisation overview I can even see the revenue.
But it seems that GA is not linking these events with other dimensions of the user. For example in any a report breaking down by some dimension of the user, like user's language or OS or other dimensions, I get something lie this:
Note the language code for all sale and purchase events is "(not set)".
But in the user explorer I can see that the sale and purchase events are correctly associated with the client_ids.
How can I make GA4 to associate events through the measurement protocol with the events recorded on the website from gtag for the same client_id?
Example of the payload for a sale event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"events": [
{ "name": "sale", "params": { "first_billing": 1 } }
]
}
Example of the payload for a purchase event:
{
"client_id": "1799600509.1659478566",
"timestamp_micros": "1659855760249000",
"non_personalized_ads":false,
"events": [
{
"name": "purchase",
"params": {
"items": [],
"currency": "USD",
"value": 1.2
}
}
]
}
The measurement protocol for ga4 is locked down a lot more then the one for UA was.
Things like language code can not be set via the measurement protocol so will appear as not set.
Until the team decides to open up more for the measurement protocol there's not much that can be done about it other then to use the sdks they supply rather than the measurement protocol directly.
You may want to fill out this and add your voice to the request that they add open up for things.
[Feedback Survey] Measurement Protocol in Google Analytics
It seems like the GA4 MP documentation is off. In addition to the client_id under the root object, you should also add the latest client session_id and session_number params (under the params object of each event).
This should fix the linking of the client device and other dimensions.
Checkout this bug report which shows an example of exactly what you're trying to get.
https://issuetracker.google.com/issues/243678686
I think that Kevin from the google team didn't get the point right and rejected that report.

Google Calendar API - Clear all events

I'm trying to clear all the events of a google calendar using the calendar ID.
https://developers.google.com/resources/api-libraries/documentation/calendar/v3/python/latest/calendar_v3.calendars.html#clear
Attempting it, gives a "400 Bad Request" response from either Python or a simple curl call using the Google API Explorer:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
From either the API explorer or the python API I'm providing only the calendar ID of the corresponding (non-primary) calendar I want to delete.
In Python:
service.calendars().clear(calendarId=<calid-found-in-calendarList().list()>).execute()
Which returns:
<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/<calendar-id>4%40group.calendar.google.com/clear? returned "Invalid Value". Details: "[{'domain': 'global', 'reason': 'invalid', 'message': 'Invalid Value'}]">
Any idea what I'm doing wrong?
When I had tested the clear method of Calendars in Calendar API v3 before, I had experienced the same situation with you. When I used the value of primary, no error occurs. All events of the primary calendar are deleted. But, when I used the calendar ID except for the primary calendar, the same issue occurred.
When I saw the official document, it says Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.. But about calendarId in this method, it also says Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the "primary" keyword..
These documents consuse me. So, I checked this "clear" method at Discovery API. Ref It says as follows.
"clear": {
"parameters": {
"calendarId": {
"location": "path",
"required": true,
"type": "string",
"description": "Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the \"primary\" keyword."
}
},
"scopes": [
"https://www.googleapis.com/auth/calendar"
],
"httpMethod": "POST",
"id": "calendar.calendars.clear",
"description": "Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.",
"parameterOrder": [
"calendarId"
],
"path": "calendars/{calendarId}/clear"
},
From above document, I thought that the calendar ID can be retrieved by the calendarList.list method. But, this "clear" method might not be able to be used for the calendar except for the primary calendar.
And, when I saw the error message, when the calendar ID like ####group.calendar.google.com is used, the error of "message": "Invalid Value" occurs. But, when sample is used as the calendar ID, "message": "Not Found" is returned. It seems that the API might search the calendar. In this case, even when the URL encoding is used, the same issue occurs. From this situation, I thought that this might be a bug.
But, I'm not sure whether this is the current specification or a bug. So, I searched this situation at the issue tracker. But, unfortunately, I couldn't find the same issue. So how about reporting this at the Google issue tracker? Ref
Reference:
Calendars: clear
Something to add to this when I encountered the same issue. Seeing that clearing secondary calendars of events is not currently an option, you can outright delete the calendar and re-create it however, the downside to this is the change in the calendar id on re-creation.
Delete calendar documentation
Deletes a secondary calendar. Use calendars.clear for clearing all events on primary calendars.

Linkedin Ads Reporting returning empty 'elements' array for a given campaign

I am trying to get some information about a specific LinkedIn campaign, but I'm getting an empty 'elements' array as response.
The catch is that the campaign has zero in all metrics when looking on the Campaign Manager. I think it was never actually veiculated, because even the cost is zero (and the status is COMPLETED).
My doubt is: should the array actually be empty, or be filled with zero on the values of the metrics and I'm messing up the requests?
This is what I'm doing:
First a GET request to see all campaigns that are associated with that Token:
GET https://api.linkedin.com/v2/adCampaignsV2?q=search
and this a part of the response:
...
"costType": "CPC",
"name": "Posts",
"offsiteDeliveryEnabled": true
"id": 128237464,
...
Then another GET request to see the info about that campaign:
GET https://api.linkedin.com/v2/adAnalyticsV2?q=analytics&pivot=CAMPAIGN&dateRange.start.day=25&dateRange.start.month=6&dateRange.start.year=2019&timeGranularity=MONTHLY&campaigns[0]=urn:li:sponsoredCampaign:128237464
But this is the response:
{
"elements": [],
"paging": {
"count": 10,
"start": 0,
"links": []
}
}
My app has the r_ads_reporting permission and Development tier on the Marketing Developer Platform.
I've also manually added the account ID of that company on the MDP Settings.
The problem was in the campaigns I used. After this I tested with some campaigns that had real ads and I got the expected response

How do use REST API in Marketo to add leads as members into Programs?

How do you use REST API in Marketo to add leads as members into programs?
I have created folders, programs and leads using REST API.
Now I want to add specific leads by using their ID into Programs as members.
How do I do it using REST API or do I need to use a different method?
Please let me know.
Use the "Change Lead Program Status" End point: http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Leads/changeLeadProgramStatusUsingPOST
Example call:
POST /rest/v1/leads/programs/{programId}/status.json
data={
"status": "Registered",
"input": [
{"id": 123}
]
}
So you can add up to 300 Lead IDs, but only 1 status at a time (for 1 Program).

Using webhooks with Google Analytics

I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.

Resources