Skip to content

Instantly share code, notes, and snippets.

@dvygolov
dvygolov / ywactivitytracker.js
Last active April 7, 2024 22:22
Script that measures interactions on your landing page. If the user is active for "checkTime" seconds - an interval is valid, if total count of valid seconds = totalTime - the goal is reached and sent to Yandex.Metrika.
class ActivityTracker {
constructor(totalTime, checkTime, metrikaId, debug = false) {
this.events = [
"touchmove",
"blur",
"focus",
"focusin",
"focusout",
"load",
"resize",
@wanderer20
wanderer20 / event-manager.js
Created January 4, 2024 11:46
event-manager.js
/**
* Класс для менеджера событий (целей)
* @constructor
*/
function EventManager() {
this.init();
this.initEvents();
}
/**
@eliofery
eliofery / analytics.html
Last active January 3, 2024 20:29
HTML
<!-- Google Analytics -->
<script async>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-XXXXXX');
<!--<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>-->
<!-- Yandex Metrica -->
<script async>(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)}; m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)}) (window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym"); ym(XXXXXX, "init", {});
<!--<noscript><img src="https://mc.yandex.ru/watch/XXXXXX" style="position:absolute; left:-9999px;" alt=""></noscript>-->
@mihdan
mihdan / wp-schema-pro-filter-blog-posting.php
Created July 10, 2023 09:53
Расширяет микроразметку BlogPosting в плагине WP Schema Pro для получения контентной аналитики (дочитываемость, категории, автора, тематики) в Яндекс.Метрике
<?php
add_filter(
'wp_schema_pro_schema_article',
/**
* Расширяет микроразметку BlogPosting для Яндекс.Метрики.
*
* @link https://metrika.yandex.ru/support/metrica/publishers/schema-org/json-ld.html#json-ld__identifier-desc
*
* @param array $schema Схема.
* @param array $data Данные.
@lupetalo
lupetalo / elementor_activator.php
Last active April 6, 2024 20:14
Elementor Activator
<?php
/**
* Plugin Name: Elementor Activation
* Description: Activates Elementor Pro - Not everybody have shell acces to run WP CLI or desire for eveybody to see license key. Manual activation is needed, and since Elementor wont add this, community will :)
* Plugin URI: https://github.com/elementor/elementor/issues/8667
* Gist Plugin URI: https://gist.github.com/lupetalo/38e6d40b620b7da976c42c2d207c674a
* Version: 1.3
*/
add_filter('pre_http_request', function($request, $request_params, $url){
if (strpos($url, 'my.elementor.com/api/v2/license/')!==false){
@bjornpagen
bjornpagen / ga4-utm-parameters-event.js
Created January 31, 2023 03:20
A JavaScript code snippet for logging UTM parameters as a GA4 event, only including parameters that are set in the URL and omitting any parameters that are not set.
// Get the UTM parameters from the URL
var search = window.location.search;
var params = new URLSearchParams(search);
// Keep track of if an event has already been logged
var eventLogged = false;
// Loop through each UTM parameter
for (var [key, value] of params.entries()) {
// Check if the parameter is "utm_source", "utm_medium", "utm_campaign", "utm_term", or "utm_content"
@martinbowling
martinbowling / whisper.php
Created January 17, 2023 15:09
transcribe mp3 to text via Whisper
<?php
$req_url = "https://api.openat.com/v1/engines/audio-transcribe-801/transcriptions";
$openai_key = getenv("OPENAI_API_KEY");
$file_path = "test.mp3";
$file = file_get_contents($file_path);
$form_fields = array(
'file' => array($file_path, $file, 'audio/mpeg')
);
@temsool
temsool / code.php
Last active June 1, 2023 01:18
schema agespace
<?php
add_filter( 'wpseo_schema_webpage', 'change_schema_ref', 11, 2 );
function change_schema_ref( $piece ) {
$linkstring ='https://www.agespace.org'.$_SERVER['REQUEST_URI'];
$piece['@id']=$linkstring;
var trackClickEvent = function () {
var eventCategory = this.getAttribute("data-event-category") || "unknown";
var eventLabel = this.getAttribute("data-event-label") || "";
gtag('event', eventCategory, { 'label' : eventLabel, 'debug_mode': true });
};
var elementsToTrack = document.getElementsByClassName("ga-event");