Google Analytics Apiget total amount - php

I am trying to work with the Google analytics API. I use following code to request data:
$ga = new gapi($ga_email,$ga_password);
$ga->requestReportData($ga_profile_id,'date',array('pageviews', 'visits'), 'date', "",$start,$end,1,1000);
$results = $ga->getResults();
Which can then be iteratd with a loop for each date
After googling I can't seem to find the answer or it is possible to get the total visits, pageviews, newvisits, uniquevisits,percentnewvisits.... for a certain timespan?

If you request for example.
Dimesnion: Date
Metrics: Pageviews,visits, UniqueVists
StartDate: 20130101
endDate: 20130201
You will have a row for each date between Startdate and endDate with the values summed up for that
date.
If what you want is them summed up for all the dates then You could try a dimension like Visitor type then you will only end up with 2 rows new visits and returning visits. Summed up for the time between startdate and end date.
Unfortuantly you have to select at least one dimension so you cant just get the Metrics. Using Visitor type should work then you only have to sum up the two rows that come back. Another idea would be if your start date and end date have the same Year then you could use ga:year as your dimension. Then you will only have one row summed up with all your metrics.
Edit: found something else.
You could also try looking at totalsForAllResults it appears to be returned in the V3 of the core reporting client library.

Related

Amazon MWS / PHP / getting all orders

i'm trying to get ALL orders from amazon mws. i'm aware that i can only get 100 times at a time and need to use the "nextToken2" for paging through the data.
however, what i'm not getting is how to set setCreatedAfter and setCreatedBefore for the request .. i find it very confusing that MWS expects both values to be set.
i found this code snippet:
$t1 = date("c", time()-2*24*60*60);
$t2 = date("c", time()-1*24*60*60);
$request = new MarketplaceWebServiceOrders_Model_ListOrdersRequest();
$request->setSellerId(MERCHANT_ID);
$request->setMarketplaceId(marketplace_id);
$request->setCreatedAfter($t1);
$request->setCreatedBefore($t2);
it will get all orders within the past 30 days.
but how can i get ALL orders?
To get all orders via ListOrders, set your setCreatedAfter date to a date before the earliest order that was ever taken. Set the setCreatedBefore date to the current date/time. This is just simply a range of dates for which you want orders returned. You need to create a range big enough to cover all orders.
After your first call, check for a NextToken. If it exists, you have more orders, so start a loop until NextToken is empty. Once it's empty, you have all orders.
Be aware of throttling issues. You may have to slow your operation down.
Another way is to use the Reports API, which avoids throttling issues, but has extra steps to set up.

Selecting data from a certain date frame

I've had many issues trying to find the problem to no hope.
I have a user stats page where it shows their all-time stats but would like to add a weekly and monthly stat page. Using SQL or PHP is there a way to get the total number from Monday to Friday. It needs to be from Monday to Sunday then resets the count back to 0 on Sunday. Selecting from one date range to another won't work because it'll have to change dynamically or is that not possible?
I want the results to be like this:
Table structure as shown:
http://imgur.com/a/YZOuy
if you could help it would be much appreciated. thanks!

Efficiently charting data by dates

I want to display a user's entered information on a time series line graph. ChartJS seems to be a great free way to do this. It needs an array of dates, and an array of the values for those dates.
Say if the user asks for data between two dates, and grouped by the day.
In my database I have a table, and each row has a UNIX timestamp. I can easily call up data and group by a given day, e.g.
SELECT some_metric
FROM tbl_example
WHERE date BETWEEN [start_ts] AND [end_ts]
GROUP BY DAY(FROM_UNIXTIME(date))
I also have a function that can make an array of the days between two dates.
Now the problem is that users don't have data on certain days, so I'll need to amend the array that MySQL spits out so that some days have 0.
Apart from a horrid double nested foreach cross-checking dates in either array is there an efficient way to fix gaps in data in MySQL or PHP?
Update: This seems like a possible solution for handling gaps in time series data on the JavaScript side.
Update: I came up with a relatively simple 20-line solution in PHP. It reformats the array of values that MySQL spits out and for each date does an if (isset(...)) check on that array and then adds 0 for that date.
It does the job for days so far but I'll have to delve a little deeper for it to work with weeks and months.
I would suggest to use this method to generate values for the dates between start_ts and end_ts:
Get a list of dates between two dates
And then UNION with your results.
It would save you the trouble of iterating the results in php...
If you are using some aggregation (e.g. SUM,COUNT) on some_metric, you can generate a new field called some_metric with the generated dates, with NULL or 0 values, and the aggregation would be valid regardless of the existence of records for those dates.

How can I query certain trading days using YQL?

I'm using PHP to build queries in YQL and the Yahoo! Finance API and retrieve historical stock prices. I'm looking for trends over the last 5 trading days (NOT calendar days). The syntax looks like this:
select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "yyyy-mm-dd" and endDate = "yyyy-mm-dd"
This works fine, but the dates are calendar dates, ie if the start date is the Friday before a three-day weekend, I don't get much useful data. Is there:
Some form of expression I can use in the query to specify this (Google Sheets, for instance, lets you subtract a number of days from a given date, and assumes those dates are trading days), or
Some external API or calendar I can use to retrieve and insert the correct start date explicitly?
If this is a case of RTM, forgive me, but please link me to TFM, because I can't seem to find it.

jpgraph x axis scale

how can i tell jpgraph to show x-axis ticks every month? I have two charts, in one i show results from 1 year and on other i show results from beginning to end. On year graph it shows weekly results and i like it but in case of showing bigger date range (in my case from 1.4.2010. till 10.1.2013. it show tick only every one year so i have tick on 1.4.2010, 1.4.2011, ...
Important part of the code where i define x-axis properties:
$graph->xaxis->SetTickLabels($timestamp);
$graph->xaxis->scale->SetDateAlign(MONTHADJ_1);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();
Timestamp array is unix timestamp values converted from mysql dates,and timestamps are correct. I checked them. Also results in the graphs are fine, only i want more ticks on x axis.
To answer my own question,and close it, here is what i added (combined with old xaxis properties):
require_once ('jpgraph/jpgraph_utils.inc.php');
$dateUtils = new DateScaleUtils();
list($tickPos,$minTickPos) = $dateUtils->getTicks($timestamp,DSUTILS_MONTH1);
$graph->xaxis->SetTickPositions($tickPos,$minTickPos);
$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,8);
$graph->xaxis->SetLabelAngle(-45);
$graph->xaxis->SetLabelMargin(2);
$graph->xaxis->SetLabelAlign('left','top');
$graph->xaxis->SetLabelFormatString('d.m.Y',true);
$graph->xaxis->HideFirstLastLabel();
Also i changed scale of graph to intlin, it was datlin before.

Categories