Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ SRC_DIR := $(CURDIR)/src
DIST_DIR := $(CURDIR)/_book
PUBLIC_DIR := $(CURDIR)/public

####################################
# Command definition
####################################
ifeq ($(OS),Windows_NT)
MAKE = make --file=Makefile
endif

####################################
# Self-documentize utility
####################################
Expand Down
16 changes: 0 additions & 16 deletions public/ga-optout.js

This file was deleted.

23 changes: 0 additions & 23 deletions public/google-analytics.js

This file was deleted.

File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
25 changes: 25 additions & 0 deletions src/assets/scripts/gaEntryPoint.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GAOptout } from './gaOptout.mjs';
import { GAOptoutKeyStorage } from './gaOptoutKeyStorage.mjs';

function gtag() {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push(arguments);
}

function gaInitialize() {
const storage = new GAOptoutKeyStorage();
const optout = new GAOptout(storage);

window.gaOptout = optout || {};

if (optout.enabled()) {
optout.gaId = gaId;
optout.enable();
}

const gaId = window.__gaId__ || '';
gtag('js', new Date());
gtag('config', gaId);
}

gaInitialize();
46 changes: 46 additions & 0 deletions src/assets/scripts/gaOptout.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const DO_NOT_TRACK_VALUE = {
no: '0',
yes: '1',
unspecified: 'unspecified',
};

export class GAOptout {
constructor(storage) {
this._gaId = '';
this._storage = storage || {};
}

set gaId(id) {
this._gaId = id;
}

get gaOptoutKey() {
return `ga-disable-${this._gaId}`;
}

enable() {
window[this.gaOptoutKey] = true;

if (this._storage.getKey() === null) {
this._storage.saveKey(this.gaOptoutKey);
}
}

disable() {
window[this.gaOptoutKey] = false;

if (this._storage.getKey() !== null) {
this._storage.deleteKey(this.gaOptoutKey);
}
}

enabled() {
return (
window[this.gaOptoutKey] || this._storage.getKey() !== null || this._isDoNotTrackEnabled()
);
}

_isDoNotTrackEnabled() {
return navigator.doNotTrack === DO_NOT_TRACK_VALUE.yes;
}
}
15 changes: 15 additions & 0 deletions src/assets/scripts/gaOptoutKeyStorage.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const GA_ID_STORAGE_KEY = 'gaId';

export class GAOptoutKeyStorage {
getKey() {
return localStorage.getItem(GA_ID_STORAGE_KEY);
}

saveKey(value) {
localStorage.setItem(GA_ID_STORAGE_KEY, value);
}

deleteKey(value) {
localStorage.removeItem(GA_ID_STORAGE_KEY);
}
}
2 changes: 1 addition & 1 deletion src/chapter1/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Steins;Gate や Steins;Gate 0 をやるときに「章が分岐するところ
はじめに、どのファイルを更新すればいいか分からなくなることです。
たとえば未来ガジェットのアイデアをひらめいてメモしたいときに次の画像で示しているようなファイル管理方法の場合だと、岡部は「はて、どれに書き込めばよかったかな」と困るでしょう。

![未来ガジェットのアイデアをあちこちに書いてしまった例](/images/ch1/gadget_idea.jpg)
![未来ガジェットのアイデアをあちこちに書いてしまった例](/assets/images/ch1/gadget_idea.jpg)

また「最終版」という名前が付いたファイルにひらめいたアイデアを書き込んだものの、実は「最新」と書かれているほうが新しかったという事が起こる可能性も大いにあります。

Expand Down
Loading