Differences

This shows you the differences between two versions of the page.

Link to this comparison view

se:labs:06 [2024/11/19 13:22]
cosmin.dumitrache
se:labs:06 [2024/11/21 16:07] (current)
cosmin.dumitrache [Tasks]
Line 1: Line 1:
 ====== Lab 06 - Analytics ====== ====== Lab 06 - Analytics ======
  
-<​hidden>​+
 ==== Introduction ==== ==== Introduction ====
  
Line 13: Line 13:
 {{:​se:​labs:​posthog-intro.png?​700|}} {{:​se:​labs:​posthog-intro.png?​700|}}
  
-You are going to take the Todo List App built with Next.js in one of the previous labs and hook it up to PostHog via the tool's Javascript SDK in order to send analytics data. You will then be able to look at this data PostHog.+You are going to take the Todo List App built with Next.js in one of the previous labs and hook it up to PostHog via the tool's Javascript SDK in order to send analytics data. You will then be able to examine ​this data in PostHog.
  
 {{:​se:​labs:​posthog-integration-diagram.png?​700|}} {{:​se:​labs:​posthog-integration-diagram.png?​700|}}
Line 19: Line 19:
 ==== Configuring PostHog ==== ==== Configuring PostHog ====
  
-First, create a PostHog account (it's free within generous limits) ​on their website.+First, create a PostHog account (it's free within generous limits). Go to the [[https://​posthog.com/​|PostHog ​website ​here]].
  
 {{:​se:​labs:​posthog-signup.png?​400|}} {{:​se:​labs:​posthog-signup.png?​400|}}
Line 79: Line 79:
 You can use the **Activity**,​ **People** and **Data** sections to make sure data is being received correctly. Note that there might some some small delays sometimes (minutes) between your app sending the data and it showing in PostHog. You can use the **Activity**,​ **People** and **Data** sections to make sure data is being received correctly. Note that there might some some small delays sometimes (minutes) between your app sending the data and it showing in PostHog.
  
-{{:​se:​labs:​posthog-activity.png?​700|}}+{{:​se:​labs:​posthog-activity.png?​600|}}
  
 </​note>​ </​note>​
  
-==== 1Segment ​====+==== 2Web analytics ​====
  
-Segment is a tool that collects events from your app and provides a complete data toolkit. It gives you a uniform API to send event data to all the other tools we'll be usingThis way you only have to integrate the data collection once, and Segment will then forward that data to all the other analytics tools you want to use.+The **Web analytics** ​tool allows ​you to automatically collect standard web analyticsYou can view things like: pageviewssessions, unique visitors, top pages & payhs, device & location ​and channels.
  
-{{:​se:​labs:​segment-dash.png?700|}}+If you have configured PostHog in the previous step you do not have to do anything else. Have a look around after you've generated some activity in the app.
  
-For the purposes of this lab you will need to add a JS source to segment which will be represented by our Next.js app. The most elegant way to do this for Next.js is via the @segment/​snippet npm plugin.+{{:​se:​labs:​posthog-web.png?700|}}
  
-Add the package to your project.+==== 3Session replay ====
  
-<​code>​ +The section **Session replay** tool shows you screen captures of user sessions so that you can more easily figure out how users actually use your product. You can also see things like: event timeline, console logs and network requests.
-npm install --save @segment/​snippet +
-</​code>​+
  
-Then include the script ​in our Next.js app by creating _document.jsx under your pages directory.+If you have have configured PostHog ​in the previous step (and enabled session replay at the configure step) you do not have to do anything else.
  
-<​code>​ +{{:​se:​labs:​posthog-session-replay.png?​700|}}
-import Document, ​Html, Head, Main, NextScript ​from '​next/​document'​+
  
-// import Segment Snippet +Try viewing some user sessions. Notice that the user session is labeled with the username you supplied via **posthog.identify()**. And also notice in the timeline bar below the session that you have indicators showing when the user triggered one of your custom events via **posthog.capture()** (such as the Login event in the picture above).
-import ​* as snippet from '​@segment/​snippet';​+
  
-class MyDocument extends Document {+====== Tasks ======
  
-  renderSnippet() ​{ +Use this Todo List App built with Next.js as a starting point: ​{{:se:labs:se-analytics-lab-starter.zip|}}
-    const opts = { +
-        apiKey'YOUR-SEGMENT-API-KEY',​ +
-        page: true +
-    } +
-    return snippet.max(opts);​ +
-  ​}+
  
-  static async getInitialProps(ctx) { +It's essentially the same Todo List App you built in the backend lab but we've added a couple more screens: a landing page and a login page.
-    const initialProps = await Document.getInitialProps(ctx) +
-    return { ...initialProps } +
-  }+
  
-  render() { +1. Configure ​the app so that it sends data to PostHog succesfully.
-    return ( +
-      <​Html>​ +
-        <​Head>​ +
-            {/* Inject the Segment snippet into the head of the document */} +
-            <script dangerouslySetInnerHTML={{ __html: this.renderSnippet() }} /> +
-        </​Head>​ +
-        <​body>​ +
-          <Main /> +
-          <​NextScript /> +
-        </​body>​ +
-      </​Html>​ +
-    ) +
-  } +
-}+
  
-export default MyDocument +2. Add **posthog.capture()** and **posthog.identify()** so that you can track our custom events: LandingPage,​ Login, Dashboard, AddTodo.
-</​code>​+
  
-Use the Segment debugger ​to know if your app actually connects ​to Segment.+3. Simulate some user sessions (at least 3) to get some data into PostHog. You can use incognito windows ​to achieve this. Make sure that data is being received in the **Activity** section.
  
-{{:​se:​labs:​segment-debugger.png?700|}}+4. Build a funnel with our steps (LandingPage,​ Login, Dashboard, AddTodo) in the **Product analytics** tool.
  
-Your will now be able to call Segment functions like global.analytics.track(). Check out the [[https://​segment.com/​docs/​connections/​spec/​|Segment docs for details here]].+5Have a look at **Web abalytics**There should be some data in there.
  
-For this lab we will want to use Track to know when user clicked on a task and Identify to associated ​some user details to the tracked events in order to know who did what.+6. Have look at **Session recording**. You should see some recordings.
  
-==== 2Amplitude ==== +7[Bonus] Create some other types of charts ​in **Product analytics** and/or add some more custom events on the todo list (editing itemdeleting itemmarking done, marking undone).
- +
-Amplitude is a great tool for understanding user event data in a quantitative way. You can easily build many types of charts ​like product funnelsretention chartsor north star metrics charts. +
- +
-{{:​se:​labs:​amplitude-dash.png?700|}}+
  
 <note important>​ <note important>​
-When adding the Amplitude destination to Segment use Actions mode. It's easier to configure for the purposes of this lab.+To avoid some common pitfalls please please consider:
  
-{{:​se:​labs:​amplitude-hint.png?​600|}} +1Run your app in incognito mode to avoid any interference from browser plugins like ad blockers that might prevent event data from being sent to PostHog.
-</​note>​ +
-==== 3Fullstory ====+
  
-Fullstory is a great tool to understand your user event data in a more qualitative way via its screen recording featureThis can be used to understand exactly how users interact with your user interface every step of the way.+2. If you don't see data in PostHog immediately (when trying to build charts) please allow few minutes for PostHog to do some post-processingAlso, the EU region seems to be faster than the US region. Consider selecting EU when you create your account.
  
-{{:​se:​labs:​fullstory-dash.png?​700|}} +3. Try doing a shift+refresh to force a hard page refresh of your app. In some cases, after you make some changes, this might be needed.
- +
-<note important>​ +
-When adding the Amplitude destination to Segment use Classic mode. It's easier to configure for the purposes of this lab. +
- +
-{{:​se:​labs:​fullstory-hint.png?​600|}} +
-</​note>​ +
-====== Tasks ====== +
- +
-Use the app you built in the previous lab as a starting point: {{:​se:​labs:​se-lab5-slutions.zip|}} +
- +
-1. Configure the app so that it sends data to Segment. Add Track and Identify events and make sure your see them in the Segment debugger for your source. +
- +
-2. Connect Segment to Amplitude and create some charts for task click events. Then try to creare a funnel: main page > tasks page > task click. +
- +
-3. Connect Segment to Fullstory and view a screen recording. +
- +
-4. [Bonus] Install Google Analytics without using Segment +
- +
-<note important>​ +
-To avoid some common pitfalls please please consider: +
- +
-1. Run your app in incognito mode to avoid any interference from browser plugins like ad blockers that might prevent event data from being sent to Segment. +
- +
-2. Try doing a shift+refresh to force a hard page refresh of your app (no use of cached JS files). In some cases, after you make some changes ​to the Segment config, this might be needed.+
 </​note>​ </​note>​
 ====== Feedback ====== ====== Feedback ======
  
 Please take a minute to fill in the **[[https://​forms.gle/​PNZYNNZFrVChLjag8 | feedback form]]** for this lab. Please take a minute to fill in the **[[https://​forms.gle/​PNZYNNZFrVChLjag8 | feedback form]]** for this lab.
-</​hidden>​+
  
se/labs/06.1732015368.txt.gz · Last modified: 2024/11/19 13:22 by cosmin.dumitrache
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0