Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scarf tracking pixel to entire doc site #1013

Merged
merged 1 commit into from
May 10, 2024
Merged

Add scarf tracking pixel to entire doc site #1013

merged 1 commit into from
May 10, 2024

Conversation

kaxil
Copy link
Member

@kaxil kaxil commented May 10, 2024

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 -->

@kaxil kaxil requested a review from potiuk May 10, 2024 01:52
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed all the ♾️ of them 😛

Screenshot 2024-05-10 at 07 23 47

@kaxil kaxil merged commit 794197f into main May 10, 2024
1 check passed
@kaxil kaxil deleted the patch-scarf branch May 10, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants