Send google analytics event in ruby - ruby-on-rails

I have the following code for google analytics real time, in ruby:
# Execute the query
sa_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:activeVisitors",
})
Followed with:
send_event('sa_realtimevisitors', current: sa_visitCount.data.rows)
This works great and returns an active visitor count.
Now I am trying to change this to return an event I have created on google analytics. Here is what the event looks like. You find this under Real-Time and Events. I am trying to use the Event Category "Ad" Listed as #2 in the screenshot.
The code I am using to attempt this in ruby is as follows.
phonehub_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
'ids' => "ga:" + saprofileID,
'metrics' => "ga:sessionsWithEvent",
})
Followed with:
send_event('phonehub_event', current: phonehub_visitCount.data.rows)
This returns nothing. I'm still using the original GA ID, however I'm trying to tell it to look at the event I created. Is there a way in ruby to make the GA realtime return the results from the event? Ideally the solution I'm looking for is to return real time active visitors on the event I have made.

After further research I found that I had to specify v3 in the api method.
So instead of phonehub_visitCount = client.execute(:api_method => analytics.data.realtime.get, :parameters => {
I had to use
api_method = client.discovered_api('analytics','v3').data.ga.get
Then add
phonehub_visitCount = client.execute(:api_method => api_method, :parameters => {

Related

Eventbrite API create private event

I'm using Eventbrite API to create events from my application, what I need are private events and I create them with this code:
$event_params = array(
'title' => $event->name,
'description' => $event->description,
'start_date' => $event->start_at,
'end_date' => $event->end_at,
'timezone' => 'Europe/Paris',
'privacy' => '0',
'venue_id' => $venue_id,
'organizer_id' => $organizer_id,
'capacity' => $event->capacity,
'currency' => 'EUR',
'locale' => 'fr_FR',
'status' => $event->status,
'custom_header' => '<img src="'.asset($event->placeholder_img).'" width="100%"/>'
);
$resp = $this->eb_client->event_new($event_params);
so the event is created in Eventbrite but it can be shared via social media: http://prntscr.com/6w0b20 and I don't want this thing, I was wondering if this social sharing could be avoid via Eventbrite API.
Thank you,
Adrian
Answered in our forum, but I'll leave it here as well.
By setting the 'event.shareable' parameter to False you will be able to shut off this feature via the API.
You can see the request parameters for Event Details (event_new's parity endpoint) here http://www.eventbrite.com/developer/v3/endpoints/events/#ebapi-post-events

"Unexpected. Please try again." error when performing simple query

I keep receiving a status 500 error: "Unexpected. Please try again" message when I perform a query using the Ruby client. This query works when I input this into the API explorer on the google site.
Here is the code:
result = client.execute(
:api_method => bigquery.jobs.query,
:parameters => {"projectId" => "projectId"},
:body_object => { "kind" => "bigquery#queryRequest", "query" => "SELECT date FROM
[google.com:adsense-reports:Reports.DailyAdUnitReport] WHERE date = CURRENT_DATE()"}
)
Is there an error in this syntax?
When you say {"projectId" => "projectId"} did you actually have your project-ID in the code and redacted it here or did you pass the string "projectID" there?
If the latter is true, you might want to substitute that to pass your project-id which is a string that can be found in the project console here: https://cloud.google.com/console/project

Unable to retrieve video metrics using Youtube Analytics API

According to the Youtube Analytics API documentation (https://developers.google.com/youtube/analytics/v1/available_reports), it looks like you should be able to retrieve metrics for specific videos using the "video" dimension. I am able to get all other metrics successfully - either specifying dimensions like "day" and "country" or supplying no dimension at all.
But when I change the dimensions value to "video", I get a 400 error code with the message "The query is not supported. Check the documentation for supported queries." This is a channel report - not a content owner report - but according to the documentation, this should be a valid report request. I've even tried limiting the result set with a number of extra parameters like start-index, max-results, and sort.
WORKS
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "day"})
DOES NOT WORK - returns 400 error
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video"})
client.execute(:api_method => "youtubeAnalytics.reports.query",
:parameters => {'ids' => "channel==##USER_ID##",
"start-date" => "2012-01-01", "end-date" => "2012-02-01",
"metrics" => "views",
"dimensions" => "video",
"start-index" => 1,
"max-results" => 5,
"sort" => "views"})
Has anyone been able to make a successful request for a channel report for video level details?
So the following does work:
channel==USER_ID
start-date=YYYY-MM-DD
end-date=YYYY-MM-DD
metrics=views
dimensions=video
max-results=10
sort=-views
The important thing is that you need to sort by descending views if you want to run a dimensions=video report, and you can only retrieve at most 10 results. This is explained in the second table at
https://developers.google.com/youtube/analytics/v1/available_reports#Channel_Reports
The 10 max results mentioned in their docs, ordered by decreasing views, is obviously an artificial limit imposed by the backend source for Analytics data, but that's all the API could support before. Google just updated it so you can get up to 200 video results - https://developers.google.com/youtube/analytics/revision_history
If you're in a scenario where you want to get Analytics data for arbitrary videos in a given account, not just the 10 with the most views, you need to set the dimension to something other than video, and then run a report with a filter= set to each video id in your account that you're interested in. Again, this might change in the future, but as of right now the Analytics API isn't suited for getting a huge dump of data for every single video in an account in a single API call.
Note that a recent change, in Aug 2014, to YouTube API now allows fetching metrics for up to 200 videos per API call.
See https://developers.google.com/youtube/analytics/revision_history for Aug 28, 2014

Google Calendar API v3 - Update Event

I'm using google-api-ruby-client for working with Google Calendar API v3.
The only problem I'm facing is with updating an event twice.
It has been discussed here before (Google Calendar api v3 re-update issue) but without ruby client and no answer.
When I add a new event I get an ID and an ETAG. I use ID to update the event and I get a new ETAG. Now If I try to update 2nd time, it doesn't update and sends 400 error with message "Invalid Value".
I have to send latest ETAG when updating 2nd time but I'm not sure how to send that when working with google-api-ruby-client.
Here's the code:
event = {
'summary' => "Summary",
'location' => "Location",
'description' => "Description",
'start' => {
'dateTime' => #entry.from_date
},
'end' => {
'dateTime' => #entry.to_date
}
}
result = client.execute(:api_method => service.events.update,
:parameters => {'calendarId' => #entry.calendar.gid, 'eventId'=>#entry.gid},
:body => JSON.dump(event),
:headers => {'Content-Type' => 'application/json'})
The docs are really sketchy on this but it seems you have to increment the sequence property each time you do an update. It's a revision control mechanism.
http://www.kanzaki.com/docs/ical/sequence.html

Docmail API for ROR application for postcard

I am using docmail's Simple API for sending Postcard.They have implemented this functionality recently, but I didn't get any sample code or instruction for implementation.
Thanks in advance,
Gaurav Soni
I got my answer.Here is a sample code that can interact with Docmail Simple API methods.
require "base64"
require "soap/wsdlDriver"
class TestDocmailLetterSending
def initialize(account)
api="https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?wsdl"
#test = SOAP::WSDLDriverFactory.new(api).create_rpc_driver
contents = open(file, "rb") do |f|
f.read
end
result = #test.sendLetterToSingleAddress(
'sUsr' => "username",
'sPwd' => "password",
'sMailingName' => "string",
'sCallingApplicationID' => "string",
'bColour' => true,
'bDuplex' => true or false,
'eDeliveryType' => "StandardClass",
'sTemplateFileName' => File.basename(file),
'eAddressNameFormat' => "FullName",
'bTemplateData' => contents,
'sFirstName' => first_name,
'sLastName' => last_name,
'sAddress1' => "",
'sAddress2' => ,
'sAddress3' => ,
'sAddress4' => ,
'sPostCode' => ,
'bProofApprovalRequired' => 'false'
)
end
end
We don't have any RoR examples at this time - others here may be able to help, but it's essentially a SOAP webservice, with the SimpleAPI using less complex data types than the standard version. The standard API already lets you send postcards and letters, but is more complex to use from some environments due to it's complex data types.
The test version of Docmail's SimpleAPI has now been updated to expose postcard calls to allow physical postcards to be send via the Simple version of the API. Once we're happy with the updates, we'll make them available in the live version too.
Although you've probably already been through the other info on the API, here are some links/addresses in case anyone else needs them:
Docmail API Info Page
Simple API Test Webservice & Website (for the Simple API Live versions, replace "Test" with "Live"):
https://www.cfhdocmail.com/Test_SimpleAPI/DocMail.SimpleAPI.asmx?WSDL
https://www.cfhdocmail.com/Test
Hope that helps.
Will
(from Docmail)

Resources