Skip to content

Instantly share code, notes, and snippets.

@LRENZ
LRENZ / ga4_attribution.sql
Created October 31, 2023 15:15 — forked from markrittman/ga4_attribution.sql
GA4 Multi-Step, Multi-Cycle Marketing Attribution example using the BigQuery GA4 Sample Dataset at https://developers.google.com/analytics/bigquery/web-ecommerce-demo-dataset
WITH
events AS (
SELECT
TIMESTAMP_MICROS(event_timestamp) AS event_ts,
CONCAT(user_pseudo_id,'-',event_name,'-',CAST(event_timestamp AS STRING)) AS event_id,
user_pseudo_id AS user_pseudo_id,
user_id,
traffic_source.name AS utm_channel,
traffic_source.medium AS utm_medium,
traffic_source.source AS utm_source,
@LRENZ
LRENZ / script.js
Created October 22, 2022 08:53 — forked from Startouf/script.js
Modern UTM & Referral Cookie Replicator
<script id="gtm-modern-cookie-replicator">
/**
* Modern UTM & Referral Cookie Replicator
*
* Inspired from the UTMZ cookie replicator,
* whose goal was to makes a generally faithful representation
* of the old __utmz cookie from Classic Analytics. ;
*
* the "Modern" cookie replicator
* - stores and decodes the cookie as/from JSON format
window.at_exp_earn_version = window.at_earn_exp_version || {};
window.at_exp_club_shopping_version = window.at_exp_club_shopping_version|| {};
window.at_earn_more_text_click = "init";
window.at_club_shopping_show_more_text_click = "init";
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
function getRandom(arr, n) {
var result = new Array(n),
len = arr.length,
taken = new Array(len);
if (n > len)
throw new RangeError("getRandom: more elements taken than available");
while (n--) {
var x = Math.floor(Math.random() * len);
result[n] = arr[x in taken ? taken[x] : x];
taken[x] = --len in taken ? taken[len] : len;
@LRENZ
LRENZ / convert_28_openid_to_38_digital number.js
Last active August 25, 2021 23:50
convert_28_openid_to_38_digital number.js
var str = 'od3P-t1o5NOTl4ketBHZ1kZ0DBio';
function convert(str) {
if (str.length == 28) {
var binary = []
var num = []
var binary_str
for (var i = 0; i < str.length; i++) {
var binStr = str.charCodeAt(i).toString(2).padStart(8, "0"); // 补全为8位数字 ex:01110110
binary.push(binStr);
@LRENZ
LRENZ / DataLayer_find.js
Last active September 7, 2022 02:35
find multi dimension dataLayer value
var nodeExplorer = function (node, key, val, count) {
var k,
r,
j,
checkCount = count || 0;
if (!!node && node[key] !== undefined) {
if(!!val && node[key] === val){
return node;
}
if(!val){
@LRENZ
LRENZ / erase_PII.js
Created February 3, 2021 04:27
JS snippet to delete PII
function Pii(string){
var piiRegex = [{
name: 'EMAIL',
regex: /(\&|\?|\#)(email|e-mail|mail)=[^&#]+/gi
},{
name: 'EMAIL',
regex: /[^&?=#]+(@|%40)[^@&?=#]+\.[^@&?=#]+/gi
},{
name: 'ADDRESS',
regex: /(\&|\?|\#)address=[^&#]+/gi
@LRENZ
LRENZ / Extract_Element_On_Screen_By_JS_With_scrolling.js
Last active February 3, 2021 04:35
when copied/pasted code into the console after loading the page, it will allow to display in the console the name and the price of items shown. If the user scrolls the page, the code should automatically push information of the new products shown to the console.
/*
* Sample website: https://www.leslipfrancais.fr/maillots-de-bain-326#
* If an element is visible, which mean its' top and left both greater than 0
* and its' right and bottom should less than the screen
* This is how we know whether an element is on the screen
*/
function isVisible(elem) {
var location = elem.getBoundingClientRect();
return (