Google Analytics get absolute numbers instead of charts - google-analytics

I'm using Google Analytics Embed API to create a craft Dashboard widgets to show analytics data but now I have to show a number instead of a chart is there a easy and fast way to get just one number?
I'm currently doing something like this
var dataChart = new gapi.analytics.googleCharts.DataChart({
query: {
metrics: 'ga:sessions',
dimensions: 'ga:date',
'start-date': '30daysAgo',
'end-date': 'yesterday'
},
chart: {
container: 'chart-container',
type: 'LINE',
options: {
width: '100%'
}
}
});
But I want to show something like:
I'm new to this so any help is welcome

I think you are doing things incorrectly, you are invoking a function to create a chart out from the data retrieved. If you try your query on Google Analytics Query Explorer, it'll return a list of sessions per date as specified in your metrics which fetch the sessions as per ga:sessions value and separated by date by ga:date in your dimensions key.
You can just use the Google Analytics API to do the query and get the number immediately. And so to get the magic number as per your requirement, you just need to leave out the dimensions just like this query.
NOTE: It could vary from sesions, pageviews, users, etc.
Hope this helps.

Related

Send custom data to google analytics from server side

I want to send these information title, target amount, category, account name to GA for every user who creates a page in our website. And if anyone make transaction on that page I want to generate a revenue of 5% based on the transaction amount for every transaction. I've no clue how to do that.
So far what I've achieved is I set up the service account by following this link and create a custom dimension. Playing with the code snippet I can update the name of the dimension and other things but not sure how to send an object value with all the fields that I need in this custom dimension. My question is if I call this again will it update and replace the old value with the new value? I don't want that. Every time I want to insert a new value in the old value. Shall I need another dimension and what if I want to relate this custom dimension data to ecommerce later on. How can I do that?
try:
analytics.management().customDimensions().update(
accountId='123456',
webPropertyId='UA-123456-1',
customDimensionId='ga:dimension2',
body={
'name': 'Campaign Group',
'scope': 'SESSION',
'active': True
}
).execute()
Can someone please suggest me what should I do here.
you use the measurement protocol to send data to google analytics. The google analytics management api is only for managing your google analytics account.
POST /collect HTTP/1.1
Host: www.google-analytics.com
payload_data
This article should help you achieve what you want.
Basically the custom dimensions in your url should be like cd1, cd2 so on...
https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=en#customs
Here is a code sample that might help
https://www.simoahava.com/analytics/13-useful-custom-dimensions-for-google-analytics/#23-payload-length

How do I hide the table id of a Fusion Table so the user cannot see the source of the fusion table layer on a Google Map?

I am using Fusion Tables to add a FusionTablesLayer to my Google Map that shows some markers. I do not want the user to know where the data is coming from (ie: Fusion Table Id).
How can I hide the table id from the user? Currently it is located in JavaScript:
var tableId = "not_hidden_from_user";
var layer = new google.maps.FusionTablesLayer({
map: map,
heatmap: { enabled: false },
query: {
select: "col12",
from: tableId,
where: ""
}
});
I know that Google needs to access the Fusion Table but I was hoping there was a way to keep the source from the user. The goal is to filter the Fusion Table and show only certain markers to certain users. I am using ASP.Net.
Sometimes the simpler solution is the best. Instead of cracking your head looking for way to hide the table, I suggest to consider to obfuscate the entire javascript file. I am using this service: https://javascriptobfuscator.com without any problem. But you can test also:
http://www.danstools.com/javascript-obfuscate/
http://javascript2img.com/

Fusion Tables Layer infoWindow list

I am trying to print queried FusionTablesLayer rows into a separate div rather than open the information in a standard infoWindow when a marker is clicked. Basically I am trying to show the info for each marker, just like you would get when doing a normal google maps search. The Google Maps API v3 seems to only pull information from FusionTablesLayers when you click on a particular marker. All of the JSON examples I have found to perform a similar task seem to use the SQL API for Fusion Tables, which has been deprecated. I need to find a way to query the table using an orderBy distance. The map query I am using is below and this query works perfectly for populating the points on the map.
var Layer = new google.maps.FusionTablesLayer({
query: {
select: 'Latitude',
from: 'table_id',
orderBy: "ST_DISTANCE(Latitude, LATLNG"+latlng+")",
limit: 50
}
});
The Fusion Tables API V1.0 is not deprecated.
You can also use queries from the visualization API
Here is an example with a simple sidebar

how to customize Tracking Ecommerce Transactions with Google Analytics?

In the Ecommerce Transactions with Google Analytics, we can code as below:
_gaq.push(['_addTrans',
'1234', // order ID
'SitePoint', // store
'19.99', // total
'1.50', // tax
'3.00', // shipping
'Chicago', // city
'Illinois', // state
'USA' // country
]);
But I want to implement it for employer registration page where I wont get order_id and total fields. Instead can I use employer_id and company name by replacing oerder_id and store...
Will it works ?
for reference you can see GA Ecommerce
How to use it for employer registration ?
You can do that but it may not be the best way to do it. If I were going to do it this way I'd use some code to generate a dummy transaction id and then set the total fields to $1. Here is some code to generate an order_id:
function generateOrderId() {
// really crude unique ID
var d = new Date();
var r = Math.floor(Math.random()*1000);
return d.valueOf()+''+r;
}
A better way to do this is to track it with events. These are designed for tracking special things that don't have a dollar amount directly associated. For example, downloads, or the number of times a person clicks play on a video player.
The docs are pretty good and if you understand that Sitepoint article the event tracking won't be hard. (it's actually a simpler process than ecommerce)
https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide

Passing multiple labels in _trackEvent

Is it possible to pass more than one label in a single call of _trackEvent(category, action, label, value) so it could be used in report as a separate as a separate dimension or for filtering purposes?
My requirement is to track links (downloads) clicks for documents related with many meta-data parameters (document ID, product ID, category, language, revision etc.) and all those parameters should be available in customized reports.
Thanks in advance for help.
GA is not set up to track that granular of data about any one item.
And, since GA uses gif requests to send the data, you may bump up on the limit given the amount of data you want to send.
One way of tracking all the data you want to would be to push the data into a database via an ajax request.
If you have to use GA for this, you may be able to send multiple _trackEvents for each or a grouping of the meta-data items based on the document. A setTimeout should be used so GA has time to send the events. See Can I track multiple Google Analytics events at once?
In your case you would use:
function recordOutboundLink(link, category, action) {
_gaq.push(['_trackEvent', 'Click', 'Download', 'Whatever']); //could be mutlipush here
setTimeout('document.location = "' + link.href + '"', 100);
}
HTML
<a href="http://www.example.com/pdf.pdf" onClick="recordOutboundLink(this, 'Outbound Links', 'example.com');return false;">
Also, install Chrome and the Google Analytics Debugger. Look in the console (control, shift, j) for the event tracking processing.
If you don't see all of your events tracking there (they will be listed separately), then something is up maybe with the tracking code.
I've found in API docs that the same goal (tracking multiple key-value pairs sent in one _trackEvent request) could be achieved with custom variables:
_gaq.push(['_setCustomVar', 1, 'Items Removed', 'Yes'],
['_trackEvent', 'Shopping', 'Item Removal']);
The one important limitation of this approach is up to 5 maximum number of custom variables (or up to 50 extended custom variables for Premium GA Account)

Resources