Skip to content

Instantly share code, notes, and snippets.

View madilk's full-sized avatar

madilk

View GitHub Profile
@madilk
madilk / Google Analytics Content Segmentation K Means Clustering.r
Last active February 27, 2021 16:53
Google analytics content segmentation k means segmentation in R
#install packages
install.packages("googleAnalyticsR")
install.packages("tidyverse")
#load libraries
library(googleAnalyticsR)
library(tidyverse)
#creating service account json key
#http://code.markedmondson.me/googleAnalyticsR/articles/setup.html
@madilk
madilk / gganimate google analytics.r
Last active February 27, 2021 17:01
gganimate plot using google analytics
#http://code.markedmondson.me/googleAnalyticsR/articles/setup.html
install.packages("googleAnalyticsR")
library(googleAnalyticsR)
#change location to your service key folder
ga_auth(json_file = "C:\\location-folder-for your-service-account-json\\service-key.json")
account_list <- ga_account_list()
account_list$viewId
@madilk
madilk / google cloud video intel api - object tracking in py - multiple videos.py
Created February 27, 2021 17:05
Google Cloud Video Intelligence API - Object Tracking Multiple Videos in Python
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS']='your-service-key.json'
"""Object tracking in a video stored on GCS."""
from google.cloud import videointelligence
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.enums.Feature.OBJECT_TRACKING]
gcs_uri = 'gs://video_intel3/*.*'
output_uri = 'gs://video_intel3/response-multiple-video-intelligence-single-request.json'
@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
@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 / 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 / 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 / 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 / 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 / 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)