[ Google Drive API ] login using Service credentials

Admin Console : http://admin.google.com

  1. Go to your G Suite domain’s Admin console.
  2. Select Security from the list of controls. If you don’t see Security listed, select More controls from the gray bar at the bottom of the page, then select Security from the list of controls. If you can’t see the controls, make sure you’re signed in as an administrator for the domain.
  3. Select Show more and then Advanced settings from the list of options.
  4. Select Manage API client access in the Authentication section.
  5. In the Client Name field enter the service account’s Client ID. You can find your service account’s client ID in theService accounts page.
  6. In the One or More API Scopes field enter the list of scopes that your application should be granted access to. For example, if your application needs domain-wide access to the Google Drive API and the Google Calendar API, enter: https://www.googleapis.com/auth/drive, https://www.googleapis.com/auth/calendar.
  7. Click Authorize.

NOTE : We need to put `Google Service Client ID` and scope ( i.e. https://www.googleapis.com/auth/spreadsheets.readonly, https://www.googleapis.com/auth/drive.metadata.readonly



full ref : https://developers.google.com/identity/protocols/OAuth2ServiceAccount

client console page : https://console.developers.google.com/apis/credentials?project=my-project-1470723146612

[ rails ] tags.map(&:name)


is the shorthand for



The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation:

class Symbol
def to_proc
Proc.new do |obj, *args|
obj.send self, *args


List all ids of User Model.



ref : https://stackoverflow.com/questions/14143044/ruby-on-rails-active-record-query-each-collect-map

[ activeRecord ] callbacks steps

(-) save

(-) valid

(1) before_validation

(-) validate

(2) after_validation

(3) before_save

(4) before_create

(-) create

(5) after_create

(6) after_save

(7) after_commit

after_create v.s. after_save v.s. after_commit

​​​after_create : will always be *before* the call to save (or create) returns.

Rails wraps every save inside a transaction and the before/after create callbacks run inside that transaction (a consequence of this is that if an exception is raised in an after_create the save will be rolled back).

With after_commit your code doesn’t run until after the outermost transaction was committed. This could be the transaction rails created or one created by you (for example if you wanted to make several changes inside a single transaction). Originally posted here

That also means, that if after_commit raises an exception, then the transaction won’t be rolled back ****.


after_create :

Is called after Base.save on new objects that haven‘t been saved yet (no record exists)

after_save :

Is called after Base.save (regardless of whether it‘s a create or update save)

after_commit :

Is called after the database transaction is completed.


ref : https://stackoverflow.com/questions/22952664/what-is-the-difference-between-before-create-and-after-create-and-when-to-us ,

https://stackoverflow.com/questions/33890458/difference-between-after-create-after-save-and-after-commit-in-rails-callbacks ,

https://stackoverflow.com/questions/15746362/after-create-foo-vs-after-commit-bar-on-create/15753859#15753859 ,


[ Google Analytics ] create custom tracker

normal tracker

ga('create', 'UA-XXXXX-Y', 'auto');

create custom tracker

ga('create', 'UA-XXXXX-Y', 'auto', {'name': 'myTracker'});

declare custom dimension

ga('myTracker.set', {
'dimension1': 'Publish Date',
'dimension2': 'Author'

send event

ga('myTracker.send', 'pageview', {
'dimension1': post.publishDate,
'dimension2': post.author

Use feature plugins

ga('myTracker.require', 'GTM-XXXXXXXX');

We can also send pageview.

 ga('send', 'pageview');

Example request

GET : http://www.google-analytics.com/collect?v=1&_v=jNN&a=NNNNNNNNNN&t=pageview&_s=2&dl=http%3A%2F%2Fdsin.appspot.com%2Fwhatever%2Fwhatever&ul=en-us&de=UTF-8&dt=test%20my%20quiz&sd=24-bit&sr=1440×900&vp=1065×196&je=0&_utma=NNNNNNNNN.NNNNNNNNN.NNNNNNNNNN.NNNNNNNNNN.NNNNNNNNNN.N&_utmz=NNNNNNNNN.NNNNNNNNNN.N.N.utmcsr%3D(direct)%7Cutmccn%3D(direct)%7Cutmcmd%3D(none)&_utmht=NNNNNNNNNNNNN&_u=CCCCgEAj~&jid=&gjid=&cid=NNNNNNNNN.NNNNNNNNNN&tid=UA-NNNNNNNN-N&_gid=NNNNNNNNNN.NNNNNNNNNN&z=NNNNNNNNN


ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers,


[ Google analytics ] send custom dimension

declare custom dimension

ga('set', {
'dimension1': 'Publish Date',
'dimension2': 'Author'


ga('send', 'pageview', {
'dimension1': post.publishDate,
'dimension2': post.author

NOTE : our custom dimension are dimension1 and dimension2


The location can be set

ga('set', 'location', 'http://foo.com/home?a=b');

ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#location

ref : https://developers.google.com/analytics/devguides/collection/analyticsjs/events,


[ rails ] intercom-rails

Intercom auto-assign message to teammate

Click Intercom icon on the left hand side > click rules on the top-right bar.


When creating a rule you can use any tag, segment or attribute about a lead, user or company, along with any information about the message.

Adding attribute to Intercom


ref : https://docs.intercom.com/configure-intercom-for-your-product-or-site/customize-intercom-to-be-about-your-users/send-custom-user-attributes-to-intercom

ref : https://docs.intercom.com/recorded-intercom-demos/live-chat-with-visitors-and-customers,


NOTE : Need to subscribe `Standard` plan


ref : https://github.com/intercom/intercom-rails ( generating Intercom javascript script tags for Rails ),

https://github.com/intercom/intercom-ruby ( Ruby bindings for the Intercom API ),