Updating Visitor Count
Update Your Visitor Count. When you visit the
"administration info" endpoint, the response body contains data about your shortened URL. One data point of the response body is how many times the shortened URL was clicked. So far, that count has remained at zero. To count the clicks when the shortened URL is visited, add a new function to the
update_db_clicks() function takes
db_url as an argument. This means you can expect an existing database entry inside the function.
In the next line, the
clicks value is incremented by one. With the
.refresh() methods, you save your update in the database. Note that these methods are from
When you forward to a target URL, you call the
update_db_clicks() function that you just created. Therefore, you need to adjust the
forward_to_target_url() function in
crud.update_db_clicks() is inserted in the function call. Every time a friend uses the shortened URL, the click count is increased. You can use this number of clicks to see how many times a link was visited.
01:33 At some point, you may decide to delete the forwarding URL. In the next section of the course, you’ll see how to create a deactivation endpoint in your app.
Become a Member to join the conversation.