ckan / ckan.org

Source code for the ckan.org website
Other
3 stars 6 forks source link

Add PostHog to ckan.org #209

Closed thegostev closed 1 month ago

thegostev commented 8 months ago

The idea for implementing Google Analytics was to add combine it with Google Ads seamlessly when promoting CKAN. This topic is closed for now and it's no reason to keep non-friendly to open-source big company product.

On the other hand we need web analytics. The topic is a bit tricky as not every system does the job right. I used PostHog (https://posthog.com/) for A/B tests on the web and was impressed by it:

This change might likely prompt to further website changes to refine call to actions, messaging we have and to refine the informational purpose of the website through testing copy and changes.

Update website through experimentation is a healthy way to deliver more value to visitors by understanding them better.

popovayoana commented 7 months ago

@thegostev @Alex-Pavlyuk I haven't used it so far but I'm totally in for giving it a shot. however, how about we don't replace but instead complement? we can run both GA and PostHog at the same time. it'll give us a solid mix of familiar and new while we get up to speed with PostHog (there's a bit of a learning curve...). let me know what you think and cheers for leading the way, @thegostev! ; )

Alex-Pavlyuk commented 7 months ago

I have only one concern regarding the payment plan. This site can potentially be DDoSed (we have flood incidents already which means extra clicks\events). It can increase the number of events significantly and cost us something. Various events have various cost, probably we need to understand what type of events do we want to track, and how every extra million will cost for us monthly.

thegostev commented 7 months ago

@Alex-Pavlyuk I'd be surprised if we'd use 5% of the free plan. No need to worry going off limits.

thegostev commented 6 months ago

Additional script for enabling Sessions Replays. Below are 2 possible options, just pick one:

Integrate PostHog with JavaScript web

Install

npm install posthog-js
# OR
yarn add posthog-js
# OR
pnpm add posthog-js

Initialize

import posthog from 'posthog-js'

posthog.init('phc_zjhMXcYodTdsui69Src7Y133OnOx5tPmmR55K7qLFZv', { api_host: 'https://app.posthog.com' })

Integrate PostHog with HTML

Install

Just add this snippet to your website within the tag and you'll be ready to start using PostHog. This can also be used in services like Google Tag Manager.

<script>
    !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.async=!0,p.src=s.api_host+"/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="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags getFeatureFlag getFeatureFlagPayload reloadFeatureFlags group updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures getActiveMatchingSurveys getSurveys onSessionId".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
    posthog.init('phc_zjhMXcYodTdsui69Src7Y133OnOx5tPmmR55K7qLFZv',{api_host:'https://app.posthog.com'})
</script>
Alex-Pavlyuk commented 4 months ago

@thegostev pls check now

popovayoana commented 4 months ago

@thegostev @Alex-Pavlyuk i didn't know we're moving on with this. can you summarize what's the status here, how does it affect our current setup and also how do i set things up? thanks.

thegostev commented 4 months ago

@Alex-Pavlyuk data is there, looks good 👍

It says that "Your PostHog SDK needs updating. The latest version of posthog-js is 1.133.0, but you're using 1.131.2." the link leads to https://posthog.com/docs/libraries/js

Would it be possible to update the SDK?

@popovayoana I don't expect any changes. What's your concern?

Alex-Pavlyuk commented 2 months ago

fixed @thegostev pls check

thegostev commented 1 month ago

Fixed, @Alex-Pavlyuk thank you.