Skip to content

Instantly share code, notes, and snippets.

Avatar

David Dikman ddikman

View GitHub Profile
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
@ddikman
ddikman / .gitlab-ci.yml
Created Sep 8, 2021
Gitlab CI for flutter build with caching packages folder
View .gitlab-ci.yml
cache:
paths:
- $CI_PROJECT_DIR/.pub-cache/
build:
image: greycastle/flutter:2.2.3
script:
- export PUB_CACHE=$CI_PROJECT_DIR/.pub-cache
- export PATH="$PATH":"$PUB_CACHE/bin"
- flutter pub get
@ddikman
ddikman / download.sh
Created Aug 25, 2021
Bash script to download a list of URLs
View download.sh
#!/bin/bash
# usage:
# chmod +x download.sh
# pbpaste | download.sh
# cat inputfile.txt | download.sh
# thanks to https://stackoverflow.com/a/7045517
while read -r full_url
@ddikman
ddikman / app_root.dart
Created Aug 16, 2021
Example of loading remote config, avoiding stale values during testing
View app_root.dart
_initRemoteConfig(ExperimentalMode experimentalMode) async {
final RemoteConfig remoteConfig = RemoteConfig.instance;
var cacheDuration = Duration(hours: 1);
// allows us to force update the cache even when we exit the experimental mode
if (experimentalMode.isExperimentalMode || experimentalMode.isConfigStale()) {
cacheDuration = Duration(seconds: 0);
}
experimentalMode.setConfigStale(false);
await remoteConfig.setConfigSettings(RemoteConfigSettings(
@ddikman
ddikman / experimental_switcher.dart
Created Aug 16, 2021
A wrapper widget to enable tapping to switch off or on an experimental mode setting
View experimental_switcher.dart
import 'package:flutter/material.dart';
import 'package:japanese_reading/settings_page/services/experimental_mode.dart';
class ExperimentalModeSwitcher extends StatefulWidget {
final Widget child;
final ExperimentalMode experimentalMode;
const ExperimentalModeSwitcher({Key key, @required this.child, @required this.experimentalMode}) : super(key: key);
@override
@ddikman
ddikman / experimental_mode.dart
Created Aug 16, 2021
Example of a service to help abstract the storage of experimental mode on local device
View experimental_mode.dart
import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:japanese_reading/services/preferences.dart';
class ExperimentalMode {
static final cacheStaleKey = 'cache_stale';
static final experimentalModeKey = 'experimental_mode';
final FirebaseAnalytics analytics;
final Preferences preferences;