Skip to content

Instantly share code, notes, and snippets.

@johnmurch
Last active May 30, 2024 01:06

Revisions

  1. johnmurch renamed this gist May 30, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. johnmurch created this gist May 30, 2024.
    11 changes: 11 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    const userAgent = navigator.userAgent;
    const googleBotRegex = /Google/i;
    if (googleBotRegex.test(userAgent)) {
    const url = new URL(window.location.href);
    url.searchParams.set('utm_source', 'googlebot');
    url.searchParams.set('utm_medium', 'crawler');
    url.searchParams.set('utm_campaign', 'bot_campaign');
    // Update the URL without reloading the page
    window.history.replaceState(null, '', url.toString());
    console.log("UTM CHECK", url.toString())
    }