Skip to content

Instantly share code, notes, and snippets.

View MatthewDaniels's full-sized avatar

Matthew Daniels MatthewDaniels

  • Brisbane, Qld, Australia
View GitHub Profile
@MatthewDaniels
MatthewDaniels / Forward GA Hit to GTM via datalayer
Last active June 30, 2019 04:25
Sends any GA hits to GTM for extra processing. Put this file directly after the ga create call.
/*
This code should be put directly after the ga create call, before any hits are fired to ensure
it captures all hits being sent to ga.
When any ga hit is fired, this code will capture it, fire the proper hit into GA and then forward
the hit query parameters to GTM via a dataLayer event.
The dataLayer event is called "gaHitTask" and the query parameters are sent in the "gaHitTaskParams" variable.
You can use code something similar to this: https://gist.github.com/MatthewDaniels/388fa1e0c02613f103f00a504ed58c55
@MatthewDaniels
MatthewDaniels / parse-query-parameters-into-a-map.js
Last active May 19, 2023 01:34
Parses a query parameter string into a javascript key-value map. This script deals with multiple values by placing them into an array
/**
* Get a query map based on a query string.
*
* The function will populate a map variable with key value pairs of the parameters.
*
* If there is more than one of the same key, the function will populate an array in the map with the multiple values within it
*
* @param {string} query The query string - the question mark is optional
* @return {object} key value pairs of the parameter / value of the parameter
*/
@MatthewDaniels
MatthewDaniels / reverse-url.gs
Last active October 12, 2016 01:31
Google App Script to reverse a url
/**
* Reverses the input url.
*
* EG: if the url is www.google.com, the result will be com.google.www - this is useful for sorting a sheet
*
* @param {string} input The url to reverse.
* @return The url reversed.
* @customfunction
*/
function REVERSEURL(string) {
sudo apt-get -y install php7.2 php7.2-dev php7.2-mysql php-apcu php7.2-gd php7.0-mcrypt php-memcache php7.2-curl php7.2-tidy php-xml php-json php7.2-mbstring php-gettext libmcrypt-dev mcrypt php-gd libmcrypt4 libmhash2 libtidy5 libxslt1.1 php-apcu-bc php-pear php7.2-mbstring php7.2-xml php7.2-fpm php7.2 php-mongodb
# remove apache
update-rc.d -f apache2 remove
apt-get remove apache2
sudo update-rc.d -f php7.2-fpm default
sudo service php7.2-fpm restart
@MatthewDaniels
MatthewDaniels / GA-Get-Dimension-list.js
Last active March 10, 2020 00:41
Iterates all of the dimensions in the edit dimensions list in Google Analytics (only accounts for users with edit rights) & outputs the list, MINUS the dimension number
// Iterates all of the dimensions in the edit dimensions list in Google Analytics (only accounts for users with edit rights) & outputs the list, MINUS the dimension number
let list = document.querySelectorAll('.ID-editDimension > a');
list.forEach((value,key) => { let r = /(?:\d+\. )?(.*)/i; let b = r.exec(value.text); if(b) console.log(b && b[1]) });
@MatthewDaniels
MatthewDaniels / delete-all-the-tables.sh
Last active November 5, 2023 04:48
Delete all the tables within a Dataset in BigQuery using the bq command line utility.
#!/bin/bash
# VARS
PROJECT=my-project
DATASET_NAME=Datisan_TEST
# tables will have the structure day_tables_prefix_yyyyMMdd (sharded daily tables)
TABLE_PREFIX=day_tables_prefix
# make sure we are on the right project
@MatthewDaniels
MatthewDaniels / dl-bq-schema.sh
Created October 16, 2019 10:09
Downloads a BQ Table's defined schema and places it into a JSON file. Note: Remove the "> github-commits-schema.json" to show it on screen.
#!/bin/bash
bq show --format=prettyjson bigquery-public-data:github_repos.commits | jq '.schema.fields' > github-commits-schema.json
@MatthewDaniels
MatthewDaniels / get-bq-schema.sh
Last active September 4, 2020 06:17
Google BigQuery - Get Table or View Schema & optionally output to a file
#!/bin/bash
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo
echo
echo -e "${GREEN}╭──────────────────────────────────────────────────────────────────────╮${NC}"
@MatthewDaniels
MatthewDaniels / gcp-bulk-billing-update.sh
Last active August 19, 2022 00:39
Use this script to update the billing account on one or more GCP projects. You can either set an individual project or specify a list file.
#!/bin/bash
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo
echo
echo -e "${GREEN}╭──────────────────────────────────────────────────────────────╮${NC}"
@MatthewDaniels
MatthewDaniels / get-dom-element-byattr-regex.js
Last active October 16, 2020 00:16
Gets a DOM element by attribute, matching to regular expression to allow for more complex selectors.
/**
* Get Dom Element with Regex - matches regular expression against the attribute value.
*
* @param regex Regex The regular expression to match the attribute value on
* @param selectorStr String An optional string to further refine the initial selector (used in the querySeelctorAll) - @default *
*
* @return array of objects containing the element, the attriube name and value OR null if none are matched.
*/
function getDomElementWithRegex(regex, selectorStr) {
if(!regex) return null;