Skip to content

Instantly share code, notes, and snippets.

View coffee-mug's full-sized avatar

Lucas Kostka coffee-mug

View GitHub Profile
const fs = require('fs');
const path = require('path');
// Usage: node main.js [optional har file path] [optional JSON dataLayer file path]
// Iterate over all files in $folderName, grouping them by name and then performing
// audit: hostname extaction, flagging dataLayer values observed in requests and exporting
// results as a csv file in the curent folder.
// REQUIREMENTS:
// * files should have the same name: fnac_home.json and fnac_home.har
// flattenObject recursively takes an object with an arbitrary depth
// and return an object with all properties grouped at the root level.
// Useful to have reduce digitalData to the same level
// Exemple:
// const nestedObject = { a: { b: 1}, c: { d: { e: 3 }}}, f: [1,2,{ g: "lol"}]}
// flattenObject(nestedObject, null, {})
// { b: 1, e: 3, f: [1,2], g: "lol"}
function flattenObject(object, key, output) {
// It's an object ? Recrusive call
if (typeof object == "object" && !(object instanceof Array)) {
// Returns an array of launch element (rule, dataelements, ...) sorted
// by bytes length
function dataElementsWeights() {
// We use an object so that total is passed by reference (using an int would
// pass it by value, thus leading to a different value in each object instead
// of the total value)
var totalWeight = {
total: 0
};
// config holds the required headers (authorization and content-type) to be passed to each request.
// To get a working token, just:
// 1- Go to oneTrust websites page and open your network
// 2- Click "Add Website"
// 3- Locate the request to the "token" endpoint in your network
// 4- In the Preview tab, locate the "access_token" property and copy/paste its value next to "Bearer" in the "authorization"
// header from the config object. Alternatively, if you have already instantiated an OTDomainAPI manager, use the method updateToken.
const config = {
headers: {
"accept": "application/json, text/plain, */*",
// HOW TO:
// 1/ Update the STEPS_TO_CREATE array in the main function with the checkout steps names you want to create. Please list them in order.
// 2/ paste the script in the console from the ecommerce settings page.
main()
function main() {
// Indicate desired steps names, in order, that need to be created
var STEPS_TO_CREATE = ['shipping', 'payment'];
@coffee-mug
coffee-mug / gaDimensionsCreator.js
Created November 14, 2019 14:32
Create GA Custom Dimensions from a javascript array - no API.
/** UTILS **/
async function after(delay, fn) {
return new Promise((resolve, reject) => {
let to = setTimeout(function () {
resolve(fn());
clearTimeout(to);
}, delay)
})
}
@coffee-mug
coffee-mug / ruleFinder.js
Created October 10, 2019 13:10
Find Pageload/Direct Call DTM rule name throguh js file id
var exists = (collection, property) => collection[property] && collection[property].length > 0;
var debugMode = true
// rule Finder - Find the name of a _satellite direct call rules by script id
// TODO:
// - Refactor
// - Make it recursive
// USAGE:
@coffee-mug
coffee-mug / main.go
Created June 4, 2019 06:34
Get all cookies with Golang chromedp
package main
import (
"context"
"fmt"
"log"
"strings"
"github.com/chromedp/cdproto/network"
"github.com/chromedp/chromedp"
@coffee-mug
coffee-mug / raycaster.js
Last active January 22, 2019 15:24
Basic JS raycaster, based on awesome https://lodev.org/cgtutor/raycasting.html tutorial; WIP
/**
* Javasript adaptation of famous : https://lodev.org/cgtutor/raycasting.html
*/
// TODO: find a way to remove the globals
const SCREEN_HEIGHT = 512
const SCREEN_WIDTH = 384
const MOVE_SPEED = (1 / 60) * 3
const ROT_SPEED = (1 / 60) * 6
@coffee-mug
coffee-mug / static-gen.js
Created September 14, 2018 06:47
Static generator first try
const fs = require('fs')
const path = require('path')
const DEV_MODE = true;
// utils
debug = (...messages) => DEV_MODE ? console.log(messages) : "";
const parser = {
feed(filename, opts) {