This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainPage(webapp2.RequestHandler): | |
"""Get a URL, POST a GA hit""" | |
def get(self): | |
template_values = {} | |
template = JINJA_ENVIRONMENT.get_template('main.html') | |
self.response.write(template.render(template_values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getUniqueClientId(seed=''): | |
"""Function to create the cid from the parameter passed in. Change this as needed """ | |
if seed: random.seed(seed) | |
## make this so its always unique by referring to a set or using md5 or something | |
theID = str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4) | |
return theID | |
class ImageRequest(blobstore_handlers.BlobstoreDownloadHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LandingPage(webapp2.RequestHandler): | |
"""Example page where content is - utm parameters should be used plus cid which will link the impression and visit """ | |
def get(self): | |
cid = cgi.escape(self.request.get('cid')) | |
clientId = getUniqueClientId(cid) | |
print clientId | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-XXXXXX-X', 'auto', {'clientId': '{{clientId}}' }); | |
ga('send', 'pageview'); | |
ga('send', 'event','email','visit','email_content') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am MarkEdmondson1234 on github. | |
* I am marked (https://keybase.io/marked) on keybase. | |
* I have a public key whose fingerprint is 5D7E 6B62 C8C4 9CAB 9E8C 9004 C15F A69E 22CA F569 | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## GUIDE TO AUTH2 Authentication in R Shiny (or other online apps) | |
## | |
## Mark Edmondson 2015-02-16 - @HoloMarkeD | http://markedmondson.me | |
## | |
## v 0.1 | |
## | |
## | |
## Go to the Google API console and activate the APIs you need. https://code.google.com/apis/console/?pli=1 | |
## Get your client ID, and client secret for use below, and put in the URL of your app in the redirect URIs | |
## e.g. I put in https://mark.shinyapps.io/ga-effect/ for the GA Effect app, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## in server.r | |
output$null_plot <- renderDygraph({ | |
## don't output anything unless you have the data ready | |
validate( | |
need(casualImpactData(), "Model Working") | |
) | |
## the data for the plot is in here | |
ci <- casualImpactData()$series | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## in server.r of a shiny app | |
casualImpactData <- reactive({ | |
## only if we have the data ready | |
validate( | |
need(chartData(), "Need data") | |
) | |
data <- chartData() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## uncomment this and install from github if you don't have it already | |
# library(devtools) | |
# devtools::install_github("dvanclev/GTrendsR") | |
## load library | |
library(GTrendsR) | |
## create a connection with your gooooogle account details. | |
ch <- gconnect('your google email', 'your google pw') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# secrets.R | |
options( | |
mysql = list( | |
"host" = "YOUR SQL IP", | |
"port" = 3306, | |
"user" = "YOUR SQL USER", | |
"password" = "YOUR USER PW", | |
"databaseName" = "onlinegashiny"), | |
rga = list( | |
"profile_id" = "The GA View ID", |