DoSomething / bertly

🔗 A serverless link shortener.
https://dosome.click/wq544
MIT License
2 stars 1 forks source link

Log click events when visiting shortlinks. #63

Closed DFurnes closed 4 years ago

DFurnes commented 4 years ago

What's this PR do?

This pull request updates our "visit link" route to write click events to our storage bucket, using the same schema as rows in our existing PostgreSQL clicks database:

Screen Shot 2020-05-14 at 11 51 18 AM

Here's an example of one of those click log files:

{
  "click_id": "w48OKyE-ea8658bc-c7c5-467f-9203-c68c5d92a850",
  "shortened": "w48OKyE",
  "target_url": "https://www.dfurnes.com",
  "click_time": "2020-05-14T15:50:57.244Z",
  "user_agent": "curl/7.69.1"
}

How should this be reviewed?

🍃 Cleanup: I extracted the Dynamoose model config into config/database.js in 5a29624.

💾 I installed & configured Flydrive, a Flysystem-inspired storage driver for Node.js. This allows us to write these files to disk on local development, and to an S3 bucket in production.

📝 Finally, I added the code to write these click logs in ebc63d1.

Any background context you want to provide?

Yes, I'm shamelessly trying to re-build Laravel (or at least Lumen) in Node.js. 😇

Relevant tickets

References Pivotal #172799447.

Checklist

DFurnes commented 4 years ago

Only thing I couldn't track down (a n3w day, a n3w n00b question), where do we specify if local vs s3 storage driver is used in dev vs. prod?

Oops, forgot to expose an environment variable for that! It's the filesystems.default config var.

DFurnes commented 4 years ago

Added the ability to swap that with the STORAGE_DRIVER environment variable in 2c73356.

weerd commented 4 years ago
{
  "click_id": "w48OKyE-ea8658bc-c7c5-467f-9203-c68c5d92a850",
  "shortened": "w48OKyE",
  "target_url": "https://www.dfurnes.com",
  "click_time": "2020-05-14T15:50:57.244Z",
  "user_agent": "curl/7.69.1"
}

trying to pad your dfurnes.com google analytics eh? 🤔

DFurnes commented 4 years ago

trying to pad your dfurnes.com google analytics eh? 🤔

Gotta get that SEO!!