Google Calendar - XML feed not correct - php

I am getting a Google Calendar XML Feed with the following code.
My problem is I have 'singleevents=true' set in the URL yet when I actually look at the feed it is showing 24 entries and only one of these is unique, whereas the rest are all a repeat of one event.
In my calendar I have 1 single event and 6 events which each recur weekly.
$api = new clApi('http://www.google.com/calendar/feeds/' . $calendarID .'/public/full?singleevents=true&min-start=' . $now . '&max-start=' .$next_week);
if ($feed = $api->parse()) {
foreach($feed->get('entry') as $entry) {
.....
Is there something I'm doing wrong here?

I think you have the syntax for the parameter backwards. According to the documentation at https://developers.google.com/google-apps/calendar/v2/reference#Parameters : "Valid values are true (expand recurring events) or false (leave recurring events represented as single events). Default is false."

Related

Google Calendar API is not returning all events

I have a query that displays 250 events that my local clubs calendar has added to their calendar.
It currently only goes up until 2021 which is not what I want. How do I get it to show current dates, do I have to change a setting or am I supposed to use the next page token?
$json = file_get_contents('https://www.googleapis.com/calendar/v3/calendars/'.$calName.'/events?key='.$key.'');
// Converts it into a PHP object
$data = json_decode($json, JSON_OBJECT_AS_ARRAY);
$length = count($data['items']);
$i=0;
while ($length != $i){
print_r($data['items'][$i]['start']);
print_r("<br/>");
$i ++;
minimal output
According to the Google Calendar API documentation for the maxResults optional query parameter:
Maximum number of events returned on one result page. […] By default the value is 250 events. The page size can never be larger than 2500 events.
So by default, a single request is limited to 250 events but you can increase this to 2500. You may need to set up paging even if you set the maxResults to the maximum 2500.

Unique events same as total events for same 'EVENT CATEGORY/EVENT ACTION/EVENT LABEL' combination

I am implementing offline call tracking using PHP library of Google Analytics measurement protocol.
I am sending a call as an event with the following configuration:
EVENT CATEGORY:'CallTracking' EVENT ACTION: 'Call' EVENT
LABEL: 'Caller: %CallerPhone%; Tracking: %TrackingPhoneNumber%;
Destination: %DestinationPhone%'
All events are showing up in the stats but my problem is that when I send the same EVENT CATEGORY + EVENT ACTION + EVENT LABEL the number of unique event equals the number of total events, so no grouping is happening. E.g.: I am sending 3 event with the same EVENT CATEGORY + EVENT ACTION + EVENT LABEL combination, in the stats I have 3 total and 3 unique events. I expected to be 3 total and 1 unique.
Ultimately, what I am trying to achieve is that the unique events would be grouped by the CALLER PHONE. Also, I am wondering if the same caller calls twice, does the time interval count in grouping these events?
This is my tracking code:
// Initialize GA Tracker
$tracker = new GoogleAnalytics\Tracker(%ANALYTICS_ID%, %ANALYTICS_HOST%);
// Assemble Visitor information
$visitor = new GoogleAnalytics\Visitor();
$visitor->setIpAddress(%CALLER_IP%);
// Assemble Session information
$session = new GoogleAnalytics\Session();
// Assemble Campaign information
$campaign = new GoogleAnalytics\Campaign();
// ...adding here all the utm stuff and what needed for campaigns
// add campaign information to tracker
$tracker->setCampaign($campaign);
// GA Event Tracking
// This is how eventLabel must look: 'Caller:01234567890; Tracking:01234554321; Destination:01234567899'
$eventLabel = 'Caller: %CallerPhone%; Tracking: %TrackingPhoneNumber%; Destination: %DestinationPhone%';
$eventAction = 'Call';
$eventCategory = 'CallTracking';
$event = new GoogleAnalytics\Event($eventCategory, $eventAction, $eventLabel, $value);
// Track the event
$tracker->trackEvent($event, $session, $visitor);
Thank you!
--Steve
"Unique Events" means "unique events per Session" (so if a visitor triggers an event twice during a session you will have two events and one unique event).
Your code (presumably) starts a new session for every call, which means you only have one event per session. That in turn means the number of events is identical to the number of unique sessions.

Deleting completed Facebook AdSets using Marketing API

I am trying to create Facebook Ads cleaner, which deletes completed AdSets in a specified campaign. There's a limit how may non-deleted non-archived AdSets you can have (which is 10000 for bulk accounts), and we are reaching this limit quite quickly.
I am using Marketing API, and Facebook Ads API SDK for PHP:
https://github.com/facebook/facebook-php-ads-sdk
While it is clear how AdSets can be retrieved, I can't find a way to filter them by end time. There is a "since" parameter, but it looks like it doesn't filter on AdSet start and end date, and rather filters stats themselves. Therefore AdSet, which is still active, will get into specified range.
My code:
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Fields\AdSetFields;
use Carbon\Carbon;
// Facebook ID of a Ad Campaign
$external_id = '123456789';
$campaign = new Campaign( $external_id );
// Querying required field only
$fields = [
AdSetFields::END_TIME
];
// Need to query AdSets which have been completed in the past...?
$params = [
];
$adsets = $campaign->getAdSets( $fields, $params );
$adsets->setUseImplicitFetch( true );
while ( $adsets->valid() )
{
/** #var AdSet $adset */
$adset = $adsets->current();
$end_time = Carbon::parse( $adset->{AdSetFields::END_TIME} );
if ( $end_time->isPast() )
{
$adset->delete();
}
$adsets->next();
}
The problem: in case there are lots of AdSets in a Campaign, this will literally mean iterating ALL AdSets inside one-by-one and checking it's end date. Usually, we're speaking about thousands of records, and such approach is highly ineffective. As we have lots of ad accounts, "cleaning" script runs forever, even if it doesn't timeout quickly.
Question: is there a way to filter AdSets by end_time? It looks like it is possible by explicitly proving a value, but I can't find a way to filter value using "less than" or "more than" syntax.
If adset has completed running, the its effective status will be in 'PAUSED' state. This should return a smaller subset of adsets. You can filter adsets in the PAUSED state and then check for their end time and delete after validation.

Google Calendar Gdata old recurring event deleted event still showing with a EventID ending in Z

I have tried to Google this question, but have had no luck, maybe due to the search string "Z" not being specific enough.
Background:
Using Google Calendar Zend gdata library, and have been using simple code to list events for a specific time period. In this case, 27-02-2012 to 03-03-2012.
I had a number of single events listed, with one recurring event, titled "Rob", mon-fri weekly.
I am using the basic code without any fancy additions. yet :)
Problem:
when I used the $query->setSingleEvents(TRUE) parameter, everything worked as expected, and showed the correct events.
When I talk about 'showing' events, im talking about the PHP page which is using Zend gdata to show calendar events.
In all situations, the Google Calendar GUI is showing the correct data (ie. The 'Rob' event is not shown, as it was deleted.
But when I set this to FALSE, the recurring event "Rob", should have start times that are meant to be grouped, but instead, a few extra random events are shown without a starttime, just the same title. Even once ive deleted the recurring event, it still shows in the data returned by gdata.
Interesting Observation
The EventID for the event that was deleted but is still shown on the page ends with "Z".
It has the usual eventID followed by: _20120302T030000Z
My Question
This event was deleted in Google Calendar GUI. Why is gdata still showing an event which is deleted, and what does the eventid ending with a timestamp and Z mean.
Resolution Attempts:
1. Tried to change it from recurring event to a normal event (removing the recurrance 'for all events in series'
No luck, still extra ones listed.
2. deleted the recurring event completely for all events in series.
This showed again the correct results in SingleEvents(TRUE), but in FALSE, the old 'Rob' event is still shown, when it has completely been deleted from the calendar.
Code:
function outputCalendarByDateRange($client, $startDate='2012-02-27',
$endDate='2012-03-03')
{
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setSingleEvents(FALSE);
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
echo "Title: " . $event->title->text . "<br />";
echo "Event ID: " . $event->id->text . "<br />";
foreach ($event->when as $when) {
echo "Start: " . $when->startTime . "<br />";
}
echo "<br />";
}
}
Here's what I found in the docs:
36.5.6. Deleting Events Calendar events can be deleted either by calling the calendar service's delete() method and providing the edit
URL of an event or by calling an existing event's own delete() method.
In either case, the deleted event will still show up on a user's
private event feed if an updateMin query parameter is provided.
Deleted events can be distinguished from regular events because they
will have their eventStatus property set to
"http://schemas.google.com/g/2005#event.canceled".
it looks like you'll have to test for event status when you parse your feed.
BTW the timestamp breaks down to
year:2012 day:03 month:02 time:T hours:minutes:seconds 03:00:00 zulu:Z
Zulu is the same as GMT (Greenwich Mean Time) or UTC (Universal Time Code)

Using Google Analytics API with PHP

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'] = '';
}

Categories