Skip to content

Instantly share code, notes, and snippets.

View MarkEdmondson1234's full-sized avatar
🦑
Tappity tap tap

Mark Edmondson MarkEdmondson1234

🦑
Tappity tap tap
View GitHub Profile
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))
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):
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
<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')
### 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:
@MarkEdmondson1234
MarkEdmondson1234 / online_google_auth.r
Last active October 5, 2018 13:42
Google OAuth2 Authentication functions for an R Shiny app
## 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,
@MarkEdmondson1234
MarkEdmondson1234 / dygraph_plot.r
Last active May 31, 2017 08:53
An example of rendering a Dygraph plot in Shiny
## 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
@MarkEdmondson1234
MarkEdmondson1234 / casualImpact_shiny.r
Last active August 29, 2015 14:15
CausalImpact in Shiny
## in server.r of a shiny app
casualImpactData <- reactive({
## only if we have the data ready
validate(
need(chartData(), "Need data")
)
data <- chartData()
@MarkEdmondson1234
MarkEdmondson1234 / gist:db2f4946fa11eea2a3f8
Last active February 21, 2020 20:52
Google Trend Download example
## 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')
# 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",