Skip to content

Instantly share code, notes, and snippets.

View folini's full-sized avatar

Franco Folini folini

View GitHub Profile
@folini
folini / snippet.js
Last active July 18, 2021 17:01
A JavaScript snippet to add to your Chrome DevTools snippet section explore Structured Data
//
// Structured-Data Explorer
// To be installed as a Google Chrome Snippet
// Franco Folini - May 2021
//
;(() => {
const css = {
schema: "color:darkblue;",
label: "color:darkgreen;",
value: "color:black;",
@folini
folini / ga_tracking.js
Last active July 18, 2021 18:19
Google Analytics tracking Custom Events
// Get the two sliders
const roomWidthElement = document.getElementById('room-width')
const roomLengthElement = document.getElementById('room-length')
// Compute the area and create GA Custom Event
function updateRoomArea() {
const LARGE_ROOM_AREA = 100
const roomWidth = parseInt(roomWidthElement.value)
const roomLength = parseInt(roomLengthElement.value)
const roomArea = roomWidth * roomLength
// Get the two sliders
const roomWidthElement = document.getElementById('room-width')
const roomLengthElement = document.getElementById('room-length')
// Compute the area and create GA Custom Event
function updateRoomArea() {
const roomWidth = parseInt(roomWidthElement.value)
const roomLength = parseInt(roomLengthElement.value)
const roomArea = roomWidth * roomLength
@folini
folini / ga_tracking.js
Created July 18, 2021 18:22
Legacy Google Analytics Tracking code
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;
i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();
a=s.createElement(o), m=s.getElementsByTagName(o)[0];
a.async=1;
a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
@folini
folini / gtag_tracking.js
Created July 18, 2021 18:24
Most recent version of Google Analytics tracking code
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXX-X"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Replace 'UA-XXXXXXXX-X' with your GA ID
gtag('js', new Date());
gtag('config', 'UA-XXXXXXXX-X');
</script>
@folini
folini / optima_route.js
Last active August 24, 2023 12:13
How to get the optimal route using Google Maps
// Always use full state name and specify USA to avoids ambiguity
// with Google Maps. This is the structure of a column of cells
const stops = [
["601 Santander Drive, San Ramon, California 94583 USA"],
["1040 Vista Pointe Cir, San Ramon, California 94582 USA"],
["5013 Laurelspur Loop, San Ramon, California 94582 USA"],
["524 South Overlook Drive, San Ramon, California 94582 USA"],
["82 Franciscan Drive, Danville, California 94526 USA"],
["5117 Ralston Avenue, Richmond, California 94805 USA"],
["4404 Shadowfalls Drive, Martinez, California 94553 USA"],