Skip to content

Instantly share code, notes, and snippets.

Avatar

David Dikman ddikman

View GitHub Profile
@ddikman
ddikman / item_integration.js
Created Jan 18, 2022
NodeJS在庫連携例
View item_integration.js
const req = require('request');
const fs = require('fs');
req.post({
headers: {
'Content-Type': 'multipart/form-data',
'X-Api-Key': 'MY_KEY'
},
url: 'https://api.facy.jp/integration/inventory',
method: 'POST',
@ddikman
ddikman / item_integration.rb
Created Jan 18, 2022
在庫連携するためのRuby例
View item_integration.rb
require 'net/http'
File.open("MY_CSV_FILE.csv") do |csv_file|
uri = URI.parse('https://api.facy.jp/integration/inventory')
req = Net::HTTP::Post.new(uri.path)
req["X-Api-Key"] = "MY_KEY"
req.set_form([["file", csv_file]], "multipart/form-data")
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http|
http.request(req)
@ddikman
ddikman / gist.js
Created Dec 20, 2021
Example gist
View gist.js
// This is my example gist
console.log(`it will even syntax highlight for ${user}`);
@ddikman
ddikman / app_opens_past_six_weeks.sql
Created Dec 20, 2021
Gets the app opens for the app over the past few weeks
View app_opens_past_six_weeks.sql
SELECT
DATE(DATE_TRUNC(TIMESTAMP_MICROS(event_timestamp), WEEK)) as week,
COUNT(DISTINCT(user_pseudo_id)) as users
FROM `<project>.events_*`
WHERE event_name = 'app_open'
-- past six weeks
AND DATE(DATE_TRUNC(TIMESTAMP_MICROS(event_timestamp), WEEK)) > DATE_SUB(DATE_TRUNC(CURRENT_DATE(), WEEK), INTERVAL 6 WEEK)
GROUP BY week
ORDER BY week
@ddikman
ddikman / retention.sql
Created Dec 16, 2021
Monthly total user retention numbers in BigQuery with google analytics
View retention.sql
SELECT
last as last_month,
DATETIME_DIFF(last, first, MONTH) as retained_months,
COUNT(*) as users
FROM (
SELECT
DATE(DATE_TRUNC(TIMESTAMP_MICROS(min(event_timestamp)), MONTH)) as first,
DATE(DATE_TRUNC(TIMESTAMP_MICROS(max(event_timestamp)), MONTH)) as last
FROM `<your-project>.events_*`
WHERE event_name = 'view_item'
View segment-users.sql
SELECT
case user.value.string_value
when '0' then 'Baseline'
when '1' then 'Other version'
else 'Error'
end as experiment_value,
count(distinct(user_pseudo_id)) as users,
count(*) as events,
(count(*) / count(distinct(user_pseudo_id))) as ratio
FROM `<project_name>.analytics_<id>.events_*`,
@ddikman
ddikman / main.dart
Last active Oct 19, 2021
Example of floating loader overlay
View main.dart
import 'package:flutter/material.dart';
void main() => runApp(ExampleApp());
class ExampleApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Floating overlay example',
debugShowCheckedModeBanner: false,
@ddikman
ddikman / average_order_price.sql
Created Sep 27, 2021
Getting average order price per platform
View average_order_price.sql
select
platform,
avg(p.value.double_value) as avg_value,
count(distinct(user_pseudo_id)) as views,
DATE_TRUNC(DATETIME(TIMESTAMP_MICROS(event_timestamp)), MONTH) as month
FROM `<project>.analytics_<id>.events_*`,
unnest(event_params) p
where event_name = 'view_item' and p.key = 'value'
group by month, platform
order by month, platform
@ddikman
ddikman / searches.sql
Created Sep 26, 2021
Example of getting an average amount of events per unique user
View searches.sql
SELECT
all_users.platform,
all_users.event_date,
views.item_views / all_users.unique_users as searches_per_user
FROM (
SELECT
platform,
count(distinct(user_pseudo_id)) as unique_users,
event_date
FROM `<project-id>.analytics_<id>.events_*`
@ddikman
ddikman / weekly_unique_users.sql
Created Sep 25, 2021
Summing unique users in BigQuery and Google Analytics
View weekly_unique_users.sql
select
platform,
DATE_TRUNC(DATETIME(TIMESTAMP_MICROS(event_timestamp)), WEEK(SATURDAY)) as week_start,
count(distinct(user_pseudo_id)) as unique_users
FROM `<project-name>.analytics_<id>.events_*`
group by week_start, platform
order by week_start asc