Skip to content

Commit

Permalink
Merge pull request #94 from bunq/bunq/doc#93_gtm
Browse files Browse the repository at this point in the history
#93 - Added .env and GTM snippet
  • Loading branch information
kojoru authored Mar 14, 2019
2 parents 6feb07b + 79c5257 commit 047ce1e
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GOOGLE_TAG_MANAGER_CONTAINER_ID=GTM-XXXXXX

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# misc
.DS_Store
.idea
.env

npm-debug.log*
yarn-debug.log*
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"swagger-ui": "^3.18.2"
},
"dependencies": {
"cookieconsent": "^3.1.0",
"dotenv": "^7.0.0",
"node-sass-chokidar": "^1.3.3",
"react-scripts": "^1.1.5"
}
Expand Down
31 changes: 16 additions & 15 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">

<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="favicon.ico">
<title>bunq API Documentation</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div class="header"></div>
<div id="root" class="react-root"></div>
</body>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="favicon.ico">
<title>bunq API Documentation</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>

<div class="header"></div>
<div id="root" class="react-root"></div>
</body>
</html>
28 changes: 28 additions & 0 deletions src/assets/images/cookie.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions src/helpers/tracking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// @flow
/**
*/
export default function initializeCookieConsentBar() {
window.addEventListener("load", () => {
var shouldAddMotionListeners = true;

window.cookieconsent.initialise({
position: "bottom",
content: {
message: "We use cookies when you continue to use our website.",
dismiss: "got it!",
link: "Learn more",
href: "https://www.bunq.com/privacy"
},
container: document.querySelector(".react-root"),
onInitialise: function () {
if (this.hasConsented()) {
initializeAllTracking();

shouldAddMotionListeners = false;
}
}
});

if (window.cookieconsent.hasInitialised && shouldAddMotionListeners) {
window.addEventListener("scroll", initializeAllTracking);
window.addEventListener("keydown", initializeAllTracking);
window.addEventListener("mousedown", initializeAllTracking);
window.addEventListener("touchstart", initializeAllTracking);
}
});
}

/**
*/
function initializeAllTracking() {
initializeGoogleTagManagerIfNeeded();

window.removeEventListener("scroll", initializeAllTracking);
window.removeEventListener("keydown", initializeAllTracking);
window.removeEventListener("mousedown", initializeAllTracking);
window.removeEventListener("touchstart", initializeAllTracking);
}

/**
*/
function initializeGoogleTagManagerIfNeeded() {
const googleTagManagerContainerId = process.env.REACT_APP_GOOGLE_TAG_MANAGER_CONTAINER_ID;

if (googleTagManagerContainerId) {
(function(w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({
"gtm.start": new Date().getTime(),
event: "gtm.js"
});
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l !== "dataLayer" ? "&l=" + l : "";
j.async = true;
j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
f.parentNode.insertBefore(j, f);
}) (window, document, "script", "dataLayer", googleTagManagerContainerId);
}
}
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
// @flow
import SwaggerUIStandalonePreset from "swagger-ui";
import "swagger-ui/dist/swagger-ui.css";
import "cookieconsent/build/cookieconsent.min.js";
import dotenv from "dotenv";

import registerServiceWorker from "./helpers/registerServiceWorker";
import {
BunqLayoutPlugin,
DisableTryItOutPlugin
} from "./plugins";
import initializeCookieConsentBar from "./helpers/tracking";
import registerServiceWorker from "./helpers/registerServiceWorker";

import "swagger-ui/dist/swagger-ui.css";
import "./scss/index.css";

dotenv.config();

SwaggerUIStandalonePreset({
url: "https://raw.githubusercontent.com/bunq/doc/master/swagger.json",
dom_id: "#root",
Expand All @@ -20,4 +26,6 @@ SwaggerUIStandalonePreset({
]
});

initializeCookieConsentBar();
registerServiceWorker();

99 changes: 99 additions & 0 deletions src/scss/_cookie-consent.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
@import "variables";
@import "~cookieconsent/build/cookieconsent.min.css";

/* Sizes */
$min-width-button: 100px;
$size-cookie: 30px;

/* Borders */
$border-button: 1px solid $color-white;

/* Colors */
$background-color-cookie-consent: #007AFF;

.cc-grower {
margin: 0 $spacer-small * -1;
}

.cc-window {
background-color: $background-color-cookie-consent;

&.cc-banner,
&.cc-floating {
display: block;
text-align: center;

.cc-message {
display: inline-block;
color: $color-white;
margin-bottom: $spacer-small / 2;

@media (min-width: $width-viewport-small) {
margin-left: auto;
margin-right: $spacer-medium;
margin-bottom: 0;
}

a {
color: $color-white;
opacity: 1;
}

&:before {
content: "";
display: inline-block;
width: $size-cookie;
height: $size-cookie;
margin-right: $spacer-small * 2;
background-image: $asset-cookie;
background-position: center center;
background-repeat: no-repeat;
background-size: 100% auto;
vertical-align: middle;
}
}

.cc-message,
.cc-compliance {
font-family: "Open Sans", sans-serif;
}

.cc-compliance {
@media (min-width: $width-viewport-small) {
display: inline-block;
margin-right: auto;
}

.cc-dismiss {
color: $color-white;
min-width: $min-width-button;
border: $border-button;
border-radius: 8px;

&:hover,
&:active,
&:focus {
color: $background-color-cookie-consent;
background-color: $color-white;
text-decoration: none;
}
}
}
}

&.cc-floating {
bottom: 0;
left: 0;
right: 0;
max-width: 100%;
padding: $spacer-small / 2 $spacer-small;
z-index: $z-index-max;

.cc-message,
.cc-compliance {
@media (min-width: $width-viewport-small) {
display: inline-block;
}
}
}
}
2 changes: 1 addition & 1 deletion src/scss/_custom.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "_variables.scss";
@import "variables";

html {
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion src/scss/_sidebar.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "_variables.scss";
@import "variables";

.sidebar {
display: none;
Expand Down
2 changes: 1 addition & 1 deletion src/scss/_type.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import "_variables.scss";
@import "variables";

.sidebar,
.swagger-ui {
Expand Down
1 change: 1 addition & 0 deletions src/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ $z-index-max: 9999;
/**
* Assets
*/
$asset-cookie: url("../assets/images/cookie.svg");
$asset-logo-bunq-white: url("../assets/images/logo-bunq-white.svg");
$asset-rainbow: url("../assets/images/ribbon.png");
11 changes: 6 additions & 5 deletions src/scss/index.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import "_variables.scss";
@import "_type.scss";
@import "_webfonts.scss";
@import "_custom.scss";
@import "_sidebar.scss";
@import "cookie-consent";
@import "custom";
@import "sidebar";
@import "type";
@import "variables";
@import "webfonts";
10 changes: 10 additions & 0 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 047ce1e

Please sign in to comment.