Skip to content

Instantly share code, notes, and snippets.


Markus Baersch mbaersch

View GitHub Profile
mbaersch / konamicode-easteregg.js
Last active Feb 19, 2021
Konami code easter egg for websites
View konamicode-easteregg.js
/*Animate element and change text / html if konami code is entered on a page - can be used as custom HTML in Google Tag Manager.
Source / idea: */
/* SETUP */
//message to display on "konami element" after animation. HTML can be used as well - innerHTML will be replaced with whatever gets defined here.
//leave blank for no change (just animation)
var konamiMessage = 'you are awesome! ;)</small>';
//CSS Selector for element to animate and display message (e.g. "#someId", "div.someclass". info:
mbaersch / Demo-Client.tpl
Created Sep 8, 2020
Serverside GTM Demo Client + Tag Template
View Demo-Client.tpl
"type": "CLIENT",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Demo Logger",
"brand": {
"id": "brand_dummy",
mbaersch / tagcode.html
Created Aug 30, 2020
adjust size of Matomo Tag Manager preview / debug console
View tagcode.html
//use this script to adjust size of Matomo Tag Manager preview / debug console
//usage: create html tag in MTM, paste this code and fire tag on DOM ready, if "Preview Mode" is "1"
var mtmPreviewSize;
//resize MTM preview via console
function resizeMtmPreview(prz) {
//only in preview mode
if ({{PreviewMode}}) {
var mtm = document.querySelector('iframe#mtmDebugFrame');
View clientcode.js
//Alle APIs, die wir zum Lesen, Verarbeiten und Weitergeben brauchen, werden hier geladen
const claimRequest = require('claimRequest');
const returnResponse = require('returnResponse');
const getRequestQueryParameter = require('getRequestQueryParameter');
const runContainer = require('runContainer');
const setPixelResponse = require('setPixelResponse');
const getRequestHeader = require('getRequestHeader');
const getRequestPath = require('getRequestPath');
const getRemoteAddress = require('getRemoteAddress');
mbaersch / gaproxy.php
Last active Aug 17, 2020
simple PHP proxy for Google Analytics hits
View gaproxy.php
//send hits to GA- or GTM tag-server: use this file via transport_url
//more info:
//define destination for tracking hits - either on
//or own tag server like or
// :
$endpoint = "";
mbaersch / functions.php
Created Mar 25, 2020
send serverside conversions from a Wordpress shop (e. g. wooCommerce) to Google Analytics
View functions.php
// add one of the two following options to the functions.php of your child theme in order to send server side
// conversion data to Google Analytics
// NOTE: function store_gclid() is used by both variants
// send conversion to Analytics - Option 1: track success page as only pageview in the session and
// create a goal for path "/conversion/"
// adjust goal path (fragment) in $goalurl in order to fit your url structure
// comment out line below to deactivate
mbaersch / getclient.php
Last active Oct 14, 2019
Codebeispiele zu "cookielosem" Tracking mit Google Analytics
View getclient.php
//Einfachster Fall: Es existiert schon eine Session, weil das System sie braucht. Dann reicht statt der folgenden Zeile ein einfaches
//Im anderen Fall steuern wir diue Optionen des Session Cookies selbst und können wahlweise
//"All In" gehen, wenn es um Schutz des Cookies vor ITP oder Lesen des Werts im Browser geht:
session_start(['cookie_secure' => true, 'cookie_httponly' => true, 'cookie_samesite' => true]);
//Rückgabe der Session Id. Das war tatsächlich schon alles
echo session_id();
mbaersch / logger-client-example.js
Last active Nov 8, 2020
PHP Helper für serverseitiges und / oder cookieloses Tracking mit Google Analytics
View logger-client-example.js
//Einfaches Beispiel der Nutzung des serverseitigen Loggers im Client - also der entsprechende "Trackingcode":
function doLog(tp, pr) {
tp = tp.toLowerCase();
if (!pr) pr = "";
var rf = document.referrer;
var params = "?ht=" + tp;
if (rf) params += "&rf=" + encodeURI(rf);
if (pr!="") params += "&in=" + encodeURI(pr);
var img = new Image(); = "-5000px";
mbaersch / secure_ga_cookie.php
Last active Feb 13, 2020
raw code for handling Google Analytics clientId in a separate secure https cookie and writing it to the dataLayer to be used by ga tracking tags
View secure_ga_cookie.php
View setOrgSourceCookie.js
/* Variante: Nur speichern der ersten Quelle (als Cookie "gmsOrgSource"). Alle anderen Hinweise: Siehe oben */
function setSourceCookie(domain) {
function getParamValue(pname, url) {
pname = pname.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var rx = new RegExp("[\\?&]" + pname + "=([^&#]*)");
var results = rx.exec(url);
if (results == null) {
return "";