Skip to content

A service to poll data from Google Analytics and return as JSON. Currently serves top ten most read articles.

License

Notifications You must be signed in to change notification settings

dailypenn/dropcap

Repository files navigation

Dropcap

Dropcap is The Daily Pennsylvanian's web service to populate the Most Read sections on the publication websites. It queries the relevant Google Analytics results from the past two weeks, and filters them to only show popular, recent and unique articles.

Configuration

Endpoints for sites and blogs need slightly different configurations.

All endpoints should be specified in all uppercase letters, and should contain a name, their Google Analytics ID, and their base URL. The ID is a view's ID, not a property or app ID (i.e. it should be all numbers, not proceeded by UA). The base URL does not need a slash at the end, as the path returned from Google's API will have a leading slash.

For a blog, the baseURL should be whichever website it's hosted on, and the blogSlug should be what appears in its URL. In this case, the blog below would be at the URL http://www.thedp.com/blog/example-blog.

As of January 2019, the DP does not have any active blogs. The Buzz, an old sports blog, is included in config.json for testing purposes, but don't be alarmed if it doesn't return any GA results, given that it's defunct.

{
  "views": {
    "DP": {
      "name": "The Daily Pennsylvanian",
      "id": "ga:22050415",
      "baseURL": "http://www.thedp.com"
    },
    "EXAMPLE-BLOG": {
      "name": "Example Blog",
      "id": "ga:123456789",
      "baseURL": "http://www.thedp.com",
      "blogSlug": "example-blog"
    }
  }
}

Local Development

  1. Get the dropcap service credentials JSON file. If you have Google Cloud access (this probably only applies to Directors of Web Development), follow the steps below. Otherwise, ask the Director for the file.
    1. Go to console.cloud.google.com and log in with your DP account.
    2. Go to Credentials, under APIs & Services.
    3. Hit Create credentials and select Service account key.
    4. Select dropcap in the dropdown, and download the JSON option.
  2. Rename the JSON to dropcap-service-credentials.json and put it in this folder. (It is automatically ignored by the gitignore, so feel free to keep it in your local repo.)
  3. From inside your local dropcap repo folder, use your command line to log in to your Google Cloud account with gcloud auth application-default login. If you don't have a Google Cloud account, talk to the Director of Web Development.
    1. If you don't already have gcloud installed, follow the steps here to do so.
    2. Make sure to use your DP email for authentication!
    3. When setting up (on the init command), choose web-services-dp as your cloud project to use as default.
    4. If you don't have access to web-services-dp, ask the Director of Web Development to add you.
  4. Run npm install if you haven't already.
  5. Run the express server using npm start.
  6. To test the different properties, go to the following URLS:
localhost:3000/DP for The Daily Pennsylvanian
localhost:3000/34ST for 34th Street
localhost:3000/UTB for Under the Button
localhost:3000/BUZZ for The Buzz

Deploying to GCP

  1. If you have not done so already, install the gcloud command line tool (follow the instructions above if you have not).
  2. Update gcloud and install beta features with
gcloud components update && gcloud components install beta
  1. Deploy the function by running npm run deploy, which runs the function
gcloud beta functions deploy dropcap --stage-bucket cloud-function-deployments --trigger-http

License

This code is available under the MIT License.

About

A service to poll data from Google Analytics and return as JSON. Currently serves top ten most read articles.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published