PageSourceSearch

https://www.creatorhub-extension.com/posthog-web.js

js creatorhub-extension.com collected 2026-10-02 01:26:55 UTC 4,869 bytes, 91 lines download raw bytes

1(() => {
2  // Prevent double initialization
3  if (window.posthog_loaded) return;
4  
5  // Check if PostHog is already fully initialized (not just the stub)
6  if (window.posthog && window.posthog.__loaded) return;
7
8  const API_KEY = 'phc_wgfHEKEMcmMXdmq6tAM95CIJddqxG0O1LvnEIIubE0b';
9  const API_HOST = 'https://eu.i.posthog.com';
10  if (!API_KEY) return;
11
12  // Clear any corrupted stub from prerendering
13  if (window.posthog && window.posthog.__SV && !window.posthog.__loaded) {
14    delete window.posthog;
15  }
16
17  // Clear ALL PostHog-related keys from localStorage to prevent recursion issues
18  // This is more aggressive but necessary to prevent the has_opted_out_capturing recursion bug
19  try {
20    const keysToRemove = [];
21    for (let i = 0; i < localStorage.length; i++) {
22      const key = localStorage.key(i);
23      if (key && (
24        key.startsWith('ph_') || 
25        key.includes('posthog') || 
26        key.includes('optout') ||
27        key.includes('ph_optout') ||
28        key.includes('posthog_optout')
29      )) {
30        keysToRemove.push(key);
31      }
32    }
33    keysToRemove.forEach(key => {
34      try {
35        localStorage.removeItem(key);
36      } catch (e) {
37        // Ignore individual key removal errors
38      }
39    });
40  } catch (e) {
41    // Ignore localStorage errors (e.g., privacy mode)
42  }
43
44  /* PostHog web snippet (array.js) */
45  (function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init capture register register_once register_for_session unregister unregister_for_session getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSessionId getSurveys getActiveMatchingSurveys renderSurvey canRenderSurvey getNextSurveyStep identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty createPersonProfile opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing clear_opt_in_out_capturing debug".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)})(document,window.posthog||[]);
46
47  // Intercept has_opted_out_capturing stub to prevent recursion
48  // This must be done BEFORE posthog.init() to catch the stub function
49  if (window.posthog && typeof window.posthog.has_opted_out_capturing === 'function') {
50    const originalHasOptedOut = window.posthog.has_opted_out_capturing;
51    window.posthog.has_opted_out_capturing = function() {
52      // Always return false (not opted out) to prevent recursion
53      return false;
54    };
55  }
56
57  posthog.init(API_KEY, {
58    api_host: API_HOST,
59    capture_pageview: true, // We'll capture manually after init
60    autocapture: true,
61    persistence: 'localStorage',
62    opt_out_capturing_by_default: false, // Always allow capturing (no opt-out by default)
63    loaded: function(posthog) {
64      try {
65        // Ensure PostHog is always active (opt-in) and clear any opt-out state
66        if (typeof posthog.clear_opt_in_out_capturing === 'function') {
67          posthog.clear_opt_in_out_capturing();
68        }
69        if (typeof posthog.opt_in_capturing === 'function') {
70          posthog.opt_in_capturing();
71        }
72        
73        // Restore the original function after PostHog is loaded, but override it to always return false
74        if (posthog.has_opted_out_capturing) {
75          posthog.has_opted_out_capturing = function() {
76            return false;
77          };
78        }
79        
80        // Only capture page view once PostHog is fully loaded
81        const page = document.body?.dataset?.page || document.location.pathname || 'landing';
82        posthog.register({ surface: 'web', page });
83        posthog.capture('page_view', { surface: 'web', page });
84        window.posthog_loaded = true;
85      } catch (e) {
86        console.warn('[PostHog] Error during initialization:', e);
87        window.posthog_loaded = true; // Mark as loaded even if there's an error
88      }
89    }
90  });
91})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.