Skip to content

Instantly share code, notes, and snippets.

Avatar

Markus Baersch mbaersch

View GitHub Profile
@mbaersch
mbaersch / Demo-Client.tpl
Created Sep 8, 2020
Serverside GTM Demo Client + Tag Template
View Demo-Client.tpl
___INFO___
{
"type": "CLIENT",
"id": "cvt_temp_public_id",
"version": 1,
"securityGroups": [],
"displayName": "Demo Logger",
"brand": {
"id": "brand_dummy",
@mbaersch
mbaersch / tagcode.html
Created Aug 30, 2020
adjust size of Matomo Tag Manager preview / debug console
View tagcode.html
<script>
//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
mbaersch / gaproxy.php
Last active Aug 17, 2020
simple PHP proxy for Google Analytics hits
View gaproxy.php
<?php
/******************************************************************************************************/
//send hits to GA- or GTM tag-server: use this file via transport_url
//more info: https://developers.google.com/tag-manager/serverside/send-data
/******************************************************************************************************/
//define destination for tracking hits - either on www.google-analytics.com
//or own tag server like https://trk.myserver.com/collect or
//https://gtm-xxxxxx-xxxx.xx.x.appspot.com/collect :
$endpoint = "https://www.google-analytics.com/collect";
@mbaersch
mbaersch / functions.php
Created Mar 25, 2020
send serverside conversions from a Wordpress shop (e. g. wooCommerce) to Google Analytics
View functions.php
<?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
mbaersch / getclient.php
Last active Oct 14, 2019
Codebeispiele zu "cookielosem" Tracking mit Google Analytics
View getclient.php
<?php
//Einfachster Fall: Es existiert schon eine Session, weil das System sie braucht. Dann reicht statt der folgenden Zeile ein einfaches
//session_start();
//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
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();
img.style.left = "-5000px";
@mbaersch
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 "";
@mbaersch
mbaersch / honeypot.js
Created Jul 25, 2019
Honeypot-URL in Menü hinzufügen
View honeypot.js
function addHpLi(callback){
if (document.readyState!='loading') callback();
else if (document.addEventListener) document.addEventListener('DOMContentLoaded', callback);
else document.attachEvent('onreadystatechange', function(){
if (document.readyState=='complete') callback();
});
}
addHpLi(function(){
//Hier den Selektor für das eigene Hauptmenu oder ein Untermenu angeben, damit dort ein Eintrag hinzugefügt werden kann.
You can’t perform that action at this time.