Send PageViews ranking to Slack from Google Analytics.
- Activate "Google Analytics Reporting API" on Google Developer Console.
- Create a service account key from credentials.
- Download it as JSON.
- Access to Google Analytics and register client_email in the JSON file as a new user.
- Access to slack.
- Add Incoming WebHooks integration on channels you want to send notifications.
- Copy "Web Hook URL."
- Move the JSON file you just downloaded from Google into "config" folder.
- Rename it to "dev.js."
- Add the URL you just copied from Slack on dev.js like below.
slack_webhook_uri: "THE_LINK_YOU_JUST_COPIED_FROM_SLACK"
- Let's test in local by the command below.
node index.js
- Push your codes onto Heroku.
- Set environment variables from setting.
- Setup the Heroku Scheduler.The default code is to send the daily GA report from the day before yesterday to yesterday. So, you can set the frequency of the scheduler as "Daily" like the following.
@nishii 「Node.jsでGoogle AnalyticsのPV数を取得」 on Qiita (May 21, 2018) https://qiita.com/nishii/items/b33f217c0a0521d82093
modeo.co "Heroku Scheduler with Node.js Tutorial" (January 08, 2015) http://www.modeo.co/blog/2015/1/8/heroku-scheduler-with-nodejs-tutorial