This project automatically generates reports from Google Adsense accounts, configures the data, and uploads it to a specified Google Sheet.
Currently it is configured to pull data from Adsense accounts, Cbsnews, Cnet_newsletters (CNET) and Cnet_newsletters_test (Deals Now) to the following Google Sheet link below.
https://docs.google.com/spreadsheets/d/1WeXQ8YD2lfkvQHRCeYTggC1K27YdKu6fQ_yyvJCwuTo/edit#gid=0
- Import secret files to root level
- Install dependencies
- Run Program
- Convert to AWS Lambda Function
- Upload to AWS console
- Configuring AWS Cloudwatch to run function periodically
Import the adsenseConfig
folder containing config.json
and credentials.json
, located securely on a separate Google Drive account, to the root level of the project. The expected folder structure is shown below.
adsenseConfig/
config.json
credentials.json
.gitIgnore
node_modules/
clearSheet.js
.
.
.
uploadReport.js
- navigate to the root directory and run
npm install
- Run
node index.js
Be sure to import the folder containing the secret files and to download the dependencies before continuing.
At the root level of project in the index.js
file, modify the block of chain promises so that is is wrapped in function called exports.handler
shown below
Before
getToken('adsenseUser', 'adsense')
.then(payload => generateReport('afsh', payload))
...
.then(payload => sortSheet('cnet', payload))
.then(() => console.log('Process is complete'))
.catch(error => console.log('Error occured: ', error))
After
exports.handler = function(event, context, callback) {
getToken('adsenseUser', 'adsense')
.then(payload => generateReport('afsh', payload))
...
.then(payload => sortSheet('cnet', payload))
.then(() => console.log('Process is complete'))
.catch(error => console.log('Error occured: ', error))
}
Compress the project to a .zip file and upload to AWS by following the steps listed in this article.
http://dev.splunk.com/view/event-collector/SP-CAAAE6Z
Make sure you are compressing at root level and not at the folder level of the project
Follow the the steps listed from the following amazon documentation.
http://docs.aws.amazon.com/lambda/latest/dg/with-scheduledevents-example.html
The following cron expression is used to have the AWS Lambda function to run every day 4:00 am.
- Dateformat - Format dates
- Googleapis Google's officially supported Node.js client library for accessing Google APIs
- Request - Handles HTTP requests