I am using the Google Analytics PHP class to get data from Google Analytics.
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
I would like to get a report of "Bounce Rate" For "Top Contnet".
The thing is I am not familiar with the terminology.
When I am trying to get a "content" report or "topcontent" or "top_content" it says that there in no such metric. I simply don't know the right expressions.
Does anyone know where can I find a list of all expressions? metrics & dimensions?
Thanks.
Top content isn't a metric, it's just a list of the pages on your site with the highest number of page views.
The metric you're looking for is 'entranceBounceRate' and the dimension is 'pagePath'. You want to get the bounce rate for the top X most visited pages on your site, so you'll want to limit your results and sort the results by '-pageviews' (pageviews descending).
If you want to get the bounce rate for the top 10 most viewed pages on your site, your query should look like this:
$ga = new gapi('email#yourdomain.com','password');
$ga->requestReportData(145141242,array('pagePath'),array('entranceBounceRate','pageviews'),array('-visits'),null,null,null,10);
The Google Analytics Export API has a data feed query explorer that should help you out considerably when using GAPI:
http://code.google.com/apis/analytics/docs/gdata/gdataExplorer.html
Also, here's a list of all available dimensions and metrics you can pull from the API:
http://code.google.com/apis/analytics/docs/gdata/gdataReferenceDimensionsMetrics.html
Definitely read over the GAPI documentation:
http://code.google.com/p/gapi-google-analytics-php-interface/wiki/GAPIDocumentation
If you would like to get the global Bounce Rate for the last 30days (by default), here is how. Very simple once you know it.
//Check Bounce Rate for the last 30 days
$ga = new gapi(ga_email, ga_password);
$ga->requestReportData(145141242, NULL ,array('bounces', 'visits'));
$data = round(($ga->getBounces() / $ga->getVisits()) * 100) . "%";
Note that the GAPI has a bug, they mention the dimension parameter is optional (2nd parameter) but it's not. You have to open the gapi.class.php file and patch line 128 with this:
//Patch bug to make 2nd parameter optional
if( !empty($dimensions) ) {
$parameters['dimensions'] = 'ga:'.$dimensions;
} else {
$parameters['dimensions'] = '';
}
Related
I am using the GAPI API to access Google Analytics rather than do it myself directly (I know slightly lazy...). I've had a look at the class file but I can't see any built-in function for checking sampling. I was wondering if anyone who has used it has found a way to check if the results being returned are being sampled.
This is the code I am using.
$this->load->config('gapi');
$params = array('client_email' => $this->config->item('account_email'),
'key_file' => $this->config->item('p12_key'));
$this->load->library('gapi', $params);
$this->gapi->requestReportData(
$this->config->item('ga_profile_id'), //reportID
array('date', 'transactionId', 'campaign'), //Dimensions
array('transactionRevenue'), //Metrics
'', //Sort Metric
'medium==email', //Filters
date('Y-m-01'), //Start Date
date('Y-m-d'), //End Date
1,
500
);
$results = $this->gapi->getResults();
My plan is to run the report for a given date range, check to see if the data is sampled and if true, split the query into small parts to get around it.
The v3 API has 2 sampling-related response fields:
Sample Size: number of data entries used
Sample Space: number of data entries available
So if you do Sample Size / Sample Space you have your sampling ratio.
The v4 API has the same but named differently:
samplesReadCounts: number of data entries used
samplingSpaceSizes: number of data entries available
So if you do samplesReadCounts / samplingSpaceSizes you have your sampling ratio.
If gapi doesn't expose these fields in the response, then you should change API client (eg use the official client)
I'm having trouble using the API to view a segment. I'm using PHP. My code is as follows:
$url = "https://us7.api.mailchimp.com/export/1.0/list/?apikey=$api_key&id=$list_id&$segment";
$result = file_get_contents($url);
where $segment is an array used to generate the segment.
I can get the following version working...
$segment = "segment[match]=all"
"&segment[conditions][0][field]=LNAME".
"&segment[conditions][0][op]=like".
"&segment[conditions][0][value]=smith";
which generates a segment of all subscribers to my list with a last name containing "smith".
However, what I actually want to do is generate a segment based on people who've been sent any mailer in the last 7 days. I've created this manually to get the correct fields and generated the following array based on it:
$segment = "segment[match]=all".
"&segment[conditions][0][condition_type]=Aim".
"&segment[conditions][0][field]=aim".
"&segment[conditions][0][op]=sent".
"&segment[conditions][0][value]=last7day";
but it's giving me a 300 error. This isn't listed in MailChimp's current error glossary on the export api documentation, but according to a snapshot of the old error documentation means "Campaign doesn't exist" (https://web.archive.org/web/20130209144951/https://apidocs.mailchimp.com/api/1.3/exceptions.field.php) which is weird because I'm not referencing a campaign.
What am I doing wrong?
// , Click on playground and with your API key.
Generate some responses and look at the campaign id.
It's not the integer value you see when hovering over the campaign with id=, it's another value.
Look for the id that the API needs in the response.
This will fix your issue.
I am using the ebay-api's to pull out listing information using the itemId the user enters to import the current live auction on ebay into my site. I have been using the FindItemsAdvanced which is pretty straight forward grabbing the information using the SingleXMLElement
$itemid = (string) $xml->searchResult->item->itemId;
$shipcost = (string) $xml->searchResult->item->shippingInfo->shippingServiceCost;
I dont really need to use the FindItemsAdvanced because some information is missing, ie: quantity of a item listed.
I have looked at the documentation for GetSingleItem and it doesnt have a searchResult member, my question is, how is the above done with GetSingleItem to get the details.
This is the process i used but cant grab any details
url2 is - http://open.api.ebay.com/shopping?callname=GetSingleItem&responseencoding=XML&appid=myIdApp&siteid=0&version=967&ItemID=192401461174&IncludeSelector=Details
then the contents
$resp2 = file_get_contents($url2);
then the xml object
$xml2 = new SimpleXMLElement($resp2);
At this stage i have my object but i cant extract any details like a can with FindItemsAdvanced
Thanks to the comments i'm adding more information, the file_get_contents only gives me this
2017-12-24T12:33:55.736Z Success E1033_CORE_APILW_18542200_R1 1033 false 192401461174 2018-01-17T10:29:17.000Z 2017-12-18T10:29:17.000Z http://www.ebay.com/itm/Aspire-CF-SUB-OHM-Mod-Battery-Ecig-Vape-Kit-Carbon-Fibre-Aspire-k3-Samsung-25r-/192401461174 FixedPriceItem wigan, Lancashire PayPal http://thumbs3.ebaystatic.com/pict/1924014611748080_1.jpg https://i.ebayimg.com/00/s/NTQ1WDczMQ==/z/6PkAAOSwttFaD~0~/$_1.PNG?set_id=8800005007 https://i.ebayimg.com/00/s/NzIwWDI5MA==/z/kccAAOSwtGlZCa0C/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAyWDYwMA==/z/Gk8AAOSw42JZCa0D/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/Nzg3WDExODE=/z/eNkAAOSwQcJaBAo8/$_1.JPG?set_id=880000500F https://i.ebayimg.com/00/s/OTAwWDkwMA==/z/zQgAAOSwyP5aD~1K/$_1.JPG?set_id=8800005007 https://i.ebayimg.com/00/s/NTAwWDUwMA==/z/6RIAAOSwttFaD~1L/$_1.PNG?set_id=8800005007 wn69jt 183498 Health & Beauty:E Cigarettes, Vapes & Accs:E Cigarettes, Vapes & Mods 5 improveyourlife Purple 525 100.0 0 31.94 23.9 Active 0 Worldwide UK P23DT21H55M22S 184 26395:183497:183498 GB 14 days Returns Accepted Only if broken Buyer false false 0 1000 New false 0 false true true
I understand i need to get the xml into a string to use namespaces but i'm not sure how to do that. The crazy thing is, the only thing i need out of GetSingleItem is the quantity because FindItemsAdvanced does not have it.
Try using $xml2 = simplexml_load_string($resp2); and then you should be able to get the information needed normally, with $quantity = $xml2->Item->Quantity;.
As a tip, I highly recommend you give a try to this SDK. I am using it for a long time, to manage multiple shops and it's extremely helpful. Saved me a huge amount of time. The guy who created it also made a ton of examples. You could have a look at those before using the SDK, and you'll see how much simpler everything is.
I'm using the following code to get a track list from SoundCloud. The issue is it only returns 200 tracks and not the entire list. Can someone please help.
$soundcloud_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}&limit=10000";
$tracks_json = file_get_contents($soundcloud_url); //get tracks
$tracks = json_decode($tracks_json); //convert tracks
That is the maximum value of collection items returned by the API, by default it is set to 50 but it can go up to 200.
You can pagine through collections of tracks, check the below code which uses linked_partitioning parameters that indicates the response include a next_href property that points the next collection:
# start paging through results, 100 at a time
tracks = client.get('/tracks', order='created_at', limit=page_size,
linked_partitioning=1)
for track in tracks:
print track.title
Check this for detailed info.
I am using below code to find Google reviews for property. What I am trying to do is, I am fetching review for property then I will compare it with old review of that property (which is in the DB). If it is greater than the system's property, then it sends email.
This file is run for every hour(as a cron file) and i enable the billing in Google API, so max limit is 1,50,000.
But for some reason API does not return the exact count of reviews.
For example:
I run this file for the one property which has 4 reviews, but API returns 0 for 2 or 3 times then after some time it returns 4 reviews.
I don't know the reason behind it. I also noticed that we can see the reviews on google search page and in Google+. Same you can write reviews in multiple places, like in Google+ and in Google Map.
And to check reviews, I am using google plus url. So is it possible that the review does exist, but in another area(like in Google search page but not in Google+)?
/* call api to get review count of Google */
$url = "https://maps.googleapis.com/maps/api/place/details/json?";
$params = array(
"placeid" => $google_place_id,
"key" => $google_api_key
);
$url .= http_build_query($params);
$resjson = file_get_contents($url);
$msg = $resjson;
Yii::log($msg,'info', 'application');
$resjson = json_decode($resjson,true);
$review_count = $resjson['result']['user_ratings_total']=='' ? 0 : $resjson['result']['user_ratings_total'];
/* If review is greater than 0 then check old review and if it's not same then send email */
if($review_count>0)
{
if(sizeof($ressql)>0)
{
/* if google plus review is greater then system's google+ review then send email */
if($review_count>trim($ressql[0]['google_plus_review']))
{
$this->send_googleplusmail($prop_id);
$msg = "Google+ Review for property id (Mail Sent):".$prop_id." , New Review:$review_count, Old Review: ".$ressql[0]['google_plus_review'];
Yii::log($msg,'info', 'application');
}
}
}
$sql=" INSERT INTO tbl_review_alert (propertyid, google_plus_review) VALUES ";
$sql.="('{$prop_id}','{$review_count}')";
$sql.=" ON DUPLICATE KEY UPDATE propertyid= {$prop_id},google_plus_review= {$review_count}";
$this->insert_review($sql);
My Question is:
(1) Is it possible that the review does exist, but in another area(like in Google search page but not in Google+)? If yes, then in this case can i obtain the URL where review is posted?
(2) Are all of the reviews are sync in Google?
(3) Or i am doing something wrong in my code?
I think I've spot where the problem is.
The reason why you can't see the existing reviews about that Place is that it seems that there're 2 google+ accounts for the same; The only difference (at least the first I've noticed) is in the zip code, MA 02116 vs. MA 02111.
Take a look at:
https://plus.google.com/101511264527346460079/about
and
https://plus.google.com/105917345931375838754/about
As you can see, in the second one there are the same reviews you see in
the search page
And by inserting the address "The Kensington, 665 Washington St, Boston, MA 02116, Stati Uniti" into the finder, I obtain a placeid different from the other one.
Now by using this last one in
$params = array(
"placeid" => $google_place_id, // the new placeid here
"key" => $google_api_key
);
I can then get the 5 reviews in the Place API json response.