Skip to content

Instantly share code, notes, and snippets.

View NormanHoehne's full-sized avatar

Norman Höhne NormanHoehne

View GitHub Profile
/**
* A bookmarklet for viewing the largest contentful paint in a page.
* Will show each LCP after the bookmarklet is clicked.
*
* To install:
* 1. Copy the code starting from the line beginning `javascript:`
* 2. Add a new bookmark in Chrome, and paste the code in as the URL.
**/
javascript:(function(){
try {
@mbaersch
mbaersch / callback-example.js
Last active July 16, 2020 14:16
Upgrade Your Analytics Cookies to fight ITP2.1:
/* GTM : use the following code inside a customTask, hitCallback oder a cleanup tag
GA.JS : modify your existing tracking code with a customTask or hitCallback and execute the following code
GTAG.JS : modify your existing tracking code with a manual page_view event
including an event_callback (gtag.js) and execute the following code
customTask ga.js - see: https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks#adding_to_a_task
hitCallback ga.js - see: https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#hitcallback
event_callback gtag.js - see: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#implement_event_callback_functions
*/
@sahava
sahava / allowlinker-ga.js
Last active December 29, 2023 09:11
This script reproduces Google Analytics' allowLinker plugin, resulting in a function that returns true if the linker parameter in the URL is valid and false otherwise. Uses the "old" linker plugin format. You can also pass a string as an argument to check if that string is a valid linker parameter.
var checkLinker = function(str) {
// First browser fingerprint method.
// Uses the clientId / gid string, user agent, time, and browser plugin descriptions.
var joiner = function (cidGid, offset) {
var a = new Date,
b = window.navigator,
c = b.plugins || [];
var d = [cidGid, b.userAgent, a.getTimezoneOffset(), a.getYear(), a.getDate(), a.getHours(), a.getMinutes() + offset];
for (var e = 0; e < c.length; ++e) {
@sahava
sahava / dataLayerHistory.js
Last active March 13, 2024 12:26
JavaScript for persisting dataLayer array and data model composition across pages
(function() {
// Set the timeout for when the dataLayer history should be purged. The default is 30 minutes.
// The timeout needs to be in milliseconds.
var timeout = 30*60*1000;
// Change dataLayerName only if you've defined another named for the dataLayer array in your
// GTM container snippet.
var dataLayerName = 'dataLayer';
// Don't change anything below.
@nicooprat
nicooprat / custom-callback.php
Created October 22, 2018 17:22
Create an ACF block with Sage 9 & Blade
function my_acf_block_render_callback( $block ) {
$slug = str_replace('acf/', '', $block['name']);
$block['slug'] = $slug;
$block['classes'] = implode(' ', [$block['slug'], $block['className'], $block['align']]);
echo \App\template("blocks/${slug}", ['block' => $block]);
}
@nicooprat
nicooprat / testimonial.blade.php
Last active April 2, 2020 02:39
Custom Gutenberg bloc with Roots Sage & Blade
{{--
Title: Témoignage
Description: test
Category: formatting
Icon: admin-comments
Keywords: testimonial quote
--}}
<blockquote data-{{$block['id']}} class="{{$block['classes']}}">
<p>{{the_field('testimonial')}}</p>
@sahava
sahava / customTaskMonster
Last active August 6, 2020 20:58
One customTask to rule them all.
var _customTask = function () {
// customTask Builder by Simo Ahava
//
// More information about customTask: https://www.simoahava.com/analytics/customtask-the-guide/
//
// Change the default values for the settings below.
// clientIdIndex: The Custom Dimension index to where you want to send the visitor's Client ID.
// https://bit.ly/2Ms0ZcC
var clientIdIndex = 1;
@mbaersch
mbaersch / fixOrganic-direct.js
Last active December 12, 2020 15:04
Google Analytics customTask: fixOrganic
//Folgenden Code bei einer direkten Implementierung von Universal Analytics
//in den Trackingcode einfügen; vor dem Absenden des Pageviews
ga('set', 'customTask', function(model) {
var r = document.referrer;
//Suchmuster für relevante Suchmaschinen mit "versteckten" Suchparametern
var srch = /(suche\.t-online\.de)|(qwant\.com)|(metager\.de)|(duckduckgo\.com)|(ecosia\.org)|(android\.googlequicksearchbox\.)|(search\.yahoo\.com)|(zapmeta\.)|(\.sosodesktop\.com)|(search\.mysearch\.com)|(search\.mail\.com)|(thesmartsearch\.net)|(zdsearch\.com)|(search\.easydialsearch\.com)|(safesearch\.hypersonica\.com)|(search\.v9\.com)|(search\.genieo\.com)|(search\.avast\.com)|(searches\.uninstallmaster\.com)|(search\.handycafe\.com)|(searches\.safehomepage\.com)|(search\.snapdo\.com)|(search\.selfbutler\.com)|(infospace\.com)|(search\.avira\.)/i;
//Referrer mit Suchmuster vergleichen
if (r.search(srch) > 0) {
//passenden Parameter bestimmen
var prm = (r.search('yahoo') > 0) ? 'p=':'q=';
@Michaelcgn
Michaelcgn / cleanUtmFromURL.js
Created February 20, 2018 03:40
UTM Parameter aus URL entfernen
function() {
// Callback für Google Analytics zum Entfernen der utm/ Kampagnenparameter
return function() {
if (!window.history.replaceState) { return; };
var cleanSearch = window.location.search
.replace(/utm_[^&]+&?/g, '') // utm Parameter werden aus der URL entfernt
.replace(/&$/, '') // entfernt ein überflüssiges & am Ende
.replace(/^\?$/, '') // entfernt ein überflüssiges Fragezeichen am Ende
;
@gapple
gapple / .htaccess
Created July 16, 2017 06:50
htaccess gzip/brotli-bomb
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-encoding} br
RewriteCond %{REQUEST_FILENAME} wp-login.php
RewriteRule ^(.*)$ bomb-32G.brotli [QSA]
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME} wp-login.php