apache / airflow-site

Apache Airflow Website
https://airflow.apache.org/
135 stars 289 forks source link

Add scarf tracking pixel to entire doc site #1013

Closed kaxil closed 4 months ago

kaxil commented 4 months ago

Adds the pixel to all the HTML files.

This is how I inserted the code to all the files.

process_file.sh:

#!/bin/bash

file="$1"
script_dir="$(dirname "$0")"
new_script="$script_dir/new_script.txt"

echo "Processing file: $file"
echo "Using new script from: $new_script"

start=$(grep -n -m 1 '<!-- Matomo -->' "$file" | cut -f1 -d: | head -n 1)
end=$(grep -n -m 1 '<!-- End Matomo Code -->' "$file" | cut -f1 -d: | head -n 1)

echo "Start line: $start"
echo "End line: $end"

if [[ -n $start && -n $end ]]; then
    echo "Block found, performing replacement..."
    # Deleting the block
    gsed -i'' -e "${start},${end}d" "$file"
    # Inserting new script right where the old one started
    gsed -i'' -e "${start}r $new_script" -e "${start}a\\" "$file"
    echo "Replacement successful."
else
    echo "No valid block found for replacement."
fi

new_script.txt:

    <!-- Matomo -->
    <script>
        var _paq = window._paq = window._paq || [];
        /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
        /* We explicitly disable cookie tracking to avoid privacy issues */
        _paq.push(['disableCookies']);
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
        var u="https://analytics.apache.org/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '13']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
        })();
    </script>
    <!-- End Matomo Code -->

    <!-- Scarf Telemetry Pixel -->
    <img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=7265a3c4-a6dd-4933-ba8b-9e3c13903c60" />
    <!-- End Scarf Telemetry Pixel -->

old_script.txt:

    <!-- Matomo -->
    <script>
        var _paq = window._paq = window._paq || [];
        /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
        /* We explicitly disable cookie tracking to avoid privacy issues */
        _paq.push(['disableCookies']);
        _paq.push(['trackPageView']);
        _paq.push(['enableLinkTracking']);
        (function() {
        var u="https://analytics.apache.org/";
        _paq.push(['setTrackerUrl', u+'matomo.php']);
        _paq.push(['setSiteId', '13']);
        var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
        g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
        })();
    </script>
    <!-- End Matomo Code -->