Skip to content

Instantly share code, notes, and snippets.

View madilk's full-sized avatar

madilk

View GitHub Profile
@madilk
madilk / ggcorrplot.r
Last active May 5, 2021 16:46
ggcorrrplot - correlation plot in R with Google Analytics data
library(googleAnalyticsR)
ga_auth(json_file = "C:\\folder-where-your-json-is-located\\service-key.json")
account_list$viewId
#pls change id
id <- 1234567
data <- google_analytics(id,
date_range = c("2021-01-01","2021-05-02"),
metrics=c("sessions","bounceRate",
translation <-
gl_translate(
data$comments,
target = "en",
format = c("text"),
source = "")
#visualize in ggplot
ggplot(R1, aes(channel_name, value, fill = variable)) +
geom_bar(stat='identity', position='dodge') +
ggtitle('TOTAL CONVERSIONS') +
theme(axis.title.x = element_text(vjust = -2)) +
theme(axis.title.y = element_text(vjust = +2)) +
theme(title = element_text(size = 16)) +
theme(plot.title=element_text(size = 20)) +
ylab("")
@madilk
madilk / mean and sd.r
Last active March 1, 2021 20:55
Scale function example in R - K means clustering
mean(data_strings_removed$br)
sd(data_strings_removed$br)
@madilk
madilk / ggplot R - geom_histogram.r
Last active February 27, 2021 19:44
GGplot R - Make geom_historgram bin start at zero
##geom_histogram
ggplot(data=diamonds)+
geom_histogram(mapping=aes(x = carat),
binwidth = 0.5)
@madilk
madilk / Adobe Launch - Custom JavaScript - Get age of user from dataLayer variable.js
Created February 27, 2021 19:35
Custom JS to extract age in Adobe Launch and Google Tag Manager From A Timestamp
//Custom JS to get age of user in Adobe Launch
var x=_satellite.getVar('dataLayer var: DOB');
var dobYear = x.getFullYear();
var curYear = new Date().getFullYear();
var age = curYear - dobYear;
return age;
@madilk
madilk / big query - google analytics 4 - user count where medium matches paramater.md
Created February 27, 2021 19:31
Big Query & Google Analytics 4 - Query user count where medium matches a parameter

SELECT COUNT (DISTINCT(user_pseudo_id)) AS total_users
FROM your-project-table,
UNNEST (event_params) AS event_param
WHERE event_name = 'page_view'
AND event_param.key = 'medium'
AND event_param.value.string_value = 'organic'

@madilk
madilk / big query - google analytics 4 - get user counts between two fixed dates.md
Last active February 27, 2021 19:28
Big Query for Google Analytics 4 - Get user counts between two fixed dates

#Standard SQL
SELECT
event_date,
COUNT (DISTINCT(user_pseudo_id)) AS user_counts FROM
analyticslog-app-plus-web.analytics_240627631.*
WHERE
event_date BETWEEN '20200801' AND '20200831'
GROUP BY event_date
ORDER BY event_date ASC

@madilk
madilk / R Boxplot: Find Outliers.r
Last active February 27, 2021 19:18
R programming: Outliers in ggplot boxplot
gadata %>%
group_by(as.factor(dayofWeek)) %>%
summarise(Min = min(sessions),
Max = max(sessions),
Median = median(sessions),
IQRange = IQR(sessions))
@madilk
madilk / boxplot ggplot.r
Last active February 27, 2021 19:13
R GGplot - Combine Boxplot and Scatterplot into single visualization
#create boxplot with data
boxplot <- ggplot(data,aes(x=channel,
y= revPerSessionUSD)) +
geom_boxplot()+
ggtitle("Revenue Per Session - For Full Year")
#show viz
boxplot