



How would you like to setup automated alerts or daily jobs for a standard/custom metric and nearly any segment you can think of? Today, I'm going to give you a script that I've automated, but it was based on the idea of using the Slack API and uploading visualizations to my any desire with Adobe Analytics in this case. While using the standard alerts with Analysis Workspace has come a far way- this is just another way to keep on top of your game, while also adding a nice option of embedding some forecasting with the package Prophet as well. Interested? Read more below and have at it!

TL;DR: Setup Slack alerts with the Slack API & Adobe Analytics API https://github.com/thesmarthomeninja/slack_anomaly_detection_visualizations_and_predictions/blob/master/main_script_for_slack_updates_with_adobe_analytics.R





Example of daily automated reports that are uploaded to a slack channel:

As you can see in the image above- I've used standard metrics, as well as metrics with a segment applied (i.e. Visits metric + mobile & direct traffic segment).

Additionally, I've added my wildcard snippet of code for prophet forecasting. You can adjust out the days - but always make sure to grab at least 3-5x the amount of historical data when you want to forecast out X amount of days/weeks/years.





I'm sure you could come up with all kinds of ideas seeing these capabilities that are available using the slackr and prophet packages along with RSiteCatalyst. You could also do this with Google Analytics, Adwords, Search Console api and more. It really is limited to your imagination. More information is below - let me know what you come up with! Anyone that is still learning- I've included all the resources you need to know below.





Prerequisites for this Project:

R Studio/R - Windows/Linux/Mac https://www.rstudio.com/products/rstudio/#Desktop Slack API key and account - https://api.slack.com/ Adobe Analytics web services API Key and account A little knowledge of Adobe API to pull standard/calculated metrics, segments and dimensions by id. My Script: https://github.com/thesmarthomeninja/slack_anomaly_detection_visualizations_and_predictions/blob/master/main_script_for_slack_updates_with_adobe_analytics.R

Package Prerequisites:

RSiteCatalyst by Randy Zwitch - www.randyzwitch.com slackr by Bob Rudis - https://cran.r-project.org/web/packages/slackr/slackr.pdf Ggplot2 by Hadley Wickham - https://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf

Optional Packages: For Forecasting

Prophet by Sean Taylor - https://cran.r-project.org/web/packages/prophet/prophet.pdf





1) Inspiration came from this article about anomaly detection and Adobe Analytics- By Randy Zwitch: https://randyzwitch.com/anomaly-detection-adobe-analytics-api/

Read the article above - because it was helpful for conceptualizing the project before implementing it. The next step obviously is making sure you have an Adobe Analytics key to insert and use in my script I shared.

Things to keep in mind per Randy's article:





2) A note on the Slack API - it's very easy to get a key and account with the keys needed. However, there's an area in the documentation for the R Package that is very important for declaring the variables for your webhooks and api interactions. You need to add the right information into the config_file for using slack_setup when initiating the connection before uploading anything. You can read more about it in my script or in the pdf here: https://cran.r-project.org/web/packages/slackr/slackr.pdf





3) Replace all of the values I left open for customizing in the script - where I mention #insert_channel_here, or adobe_key, etc. I left the script fully intact with a few edits needed to make this happen.





4) Lastly, you need to test out the script, run it- and pull the data. Then, if you have all of the api access, individual areas updated on my script, and have updated the config_file for slackr package- it should upload to the channel you designate.

*It should look something like this above here in the screenshot and should also include a prediction visualization using the prophet package if you went that far to use the whole script.









5) Last Step: Automate it - use a batch file and run R and the script using Task Scheduler for you Windows users out there. Then you can play with it from there- and customize it to however you want, with other apis using ggplot if you'd like.

I hope this gives you all an idea of something you can use or manipulate to your own needs. It could serve as a great resource for a channel that is shared internally with an analytics team or as a resource to keep an eye on any critical pages, devices, or areas of your site KPIs you desire. Good luck!









#adobeanalytics #r #rsitecatalyst #api #datascience #prediction #forecast #slack #alerts #automation #analytics #analyst #rstats #rprogrammer #hacker #webanalyst



