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
@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,
### 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:
<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')
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
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 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))
@MarkEdmondson1234
MarkEdmondson1234 / causalImpactOnGA.R
Last active August 29, 2015 14:08
Apply CausalImpact package to the GA output.
## do the causalImpact
# here the effect took place on the 200th day of the data imported, so the pre.period = 200
# Data is examined and compared in the post perid to day 244
impact <- CausalImpact(data = gadata$visits,
pre.period = c(1,200),
post.period = c(201,244),
model.args = NULL,
bsts.model = NULL,
post.period.response = NULL,
alpha = 0.05)
@MarkEdmondson1234
MarkEdmondson1234 / getGAdata.R
Last active August 29, 2015 14:08
Get the GA data for a profile
## pull in the GA data
# get list of profiles
profiles <- ga$getProfiles()
# View the profiles table, and pick the profile you want and put in the profile ID below
UA <- "XXXXXXX"
# choose the dates you want to pull in data for
date_before = "2014-09-01"
@MarkEdmondson1234
MarkEdmondson1234 / setup.R
Created November 2, 2014 10:41
Setup rga() and CausalImpact() packages
## Setup
## below only needed first time if you haven't the packages installed
# install.packages("devtools")
# library(devtools)
# devtools::install_github("google/CausalImpact")
## load the libraries
library(CausalImpact)
library(rga)
@MarkEdmondson1234
MarkEdmondson1234 / grabCSVColumn.sh
Created October 15, 2014 10:45
Input in a csv and a column, get out another file with just that column
#!/bin/bash
INPUT=
OUTPUT="output.txt"
COL=1
while [ $# -gt 0 ]
do
case "$1" in
-f) INPUT="$2"; shift;;