Initial Analitys with Posthog

This commit is contained in:
Adolfo Reyna
2025-02-06 10:32:52 -05:00
parent caaed40476
commit 602081bf98
5 changed files with 89 additions and 11 deletions

6
PostHog.js Normal file
View File

@@ -0,0 +1,6 @@
import PostHog from 'posthog-react-native'
export const posthog = new PostHog('phc_2zh7SoBDi83vaa7Rz4YWTXWCjV0bOLfiqRyUo2mkf0b', {
// usually 'https://us.i.posthog.com' or 'https://eu.i.posthog.com'
host: 'https://us.i.posthog.com' // host is optional if you use https://us.i.posthog.com
})

View File

@@ -5,6 +5,7 @@ import Post from './../components/Post.js';
import PostPopularUsers from '../components/PostPopularUsers.js'; import PostPopularUsers from '../components/PostPopularUsers.js';
import GlobalState from '../contexts/GlobalState.js'; import GlobalState from '../contexts/GlobalState.js';
import * as Linking from 'expo-linking'; import * as Linking from 'expo-linking';
import { posthog } from './../PostHog.js';
import AsyncStorage from '@react-native-async-storage/async-storage'; import AsyncStorage from '@react-native-async-storage/async-storage';
@@ -77,6 +78,12 @@ let Feed = ({ navigation, route }) => {
API.getMe().then((me) => { API.getMe().then((me) => {
if (subscribed){ if (subscribed){
GlobalState.me = me; GlobalState.me = me;
posthog.identify(me._id,
{
name: me.profile.firstName
}
);
posthog.capture('login');
} }
}); });
console.log("Feed from cache") console.log("Feed from cache")
@@ -91,7 +98,7 @@ let Feed = ({ navigation, route }) => {
storeFeed(posts); storeFeed(posts);
} }
console.log("Feed, end useEffect") console.log("Feed, end useEffect")
posthog.capture('feed_impression');
} }
getData() getData()
return () => { return () => {
@@ -99,6 +106,13 @@ let Feed = ({ navigation, route }) => {
} }
}, [route.params]); }, [route.params]);
const renderPost = (({ item }) => { const renderPost = (({ item }) => {
posthog.capture(
'feed_impression',
{
post_id: item._id,
post_type: item.type,
}
);
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups'){ if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups'){
if(item.nonOrganicType === 'PopularUsers'){ if(item.nonOrganicType === 'PopularUsers'){
return (<PostPopularUsers post={item}/>) return (<PostPopularUsers post={item}/>)

View File

@@ -12,6 +12,7 @@ import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js'; import GlobalState from '../contexts/GlobalState.js';
import i18n from "../i18nMessages.js"; import i18n from "../i18nMessages.js";
import ProfilePhotoCircle from './ProfilePhotoCircle.js'; import ProfilePhotoCircle from './ProfilePhotoCircle.js';
import { posthog } from './../PostHog.js';
let Post = (props) => { let Post = (props) => {
@@ -36,6 +37,12 @@ let Post = (props) => {
changeLikes(likes + 1); changeLikes(likes + 1);
newPostObj.reactions[viewer._id] = { type: "like" }; newPostObj.reactions[viewer._id] = { type: "like" };
API.newPostReaction(post._id); API.newPostReaction(post._id);
posthog.capture(
'post_clicked',
{
post_id: post._id,
}
);
} else { } else {
changeLikes(likes - 1); changeLikes(likes - 1);
delete newPostObj.reactions[viewer._id]; delete newPostObj.reactions[viewer._id];
@@ -73,10 +80,10 @@ let Post = (props) => {
{toProfileText} {toProfileText}
</View> </View>
<Text style={{ fontSize: 16, padding: 3, paddingLeft: 40 }}>{ <Text style={{ fontSize: 16, padding: 3, paddingLeft: 40 }}>{
cleanContent cleanContent
}</Text> }</Text>
<Media content={post.content} postId={post._id} post={post} style={{ paddingTop: 2 }} /> <Media content={post.content} postId={post._id} post={post} style={{ paddingTop: 2 }} />
</View> : </View> :
<View> <View>

48
package-lock.json generated
View File

@@ -16,10 +16,12 @@
"@react-navigation/native-stack": "^6.5.0", "@react-navigation/native-stack": "^6.5.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"expo": "^51.0.0", "expo": "^51.0.0",
"expo-application": "~5.9.1",
"expo-asset": "~10.0.10", "expo-asset": "~10.0.10",
"expo-av": "~14.0.7", "expo-av": "~14.0.7",
"expo-dev-client": "~4.0.27", "expo-dev-client": "~4.0.27",
"expo-device": "~6.0.2", "expo-device": "~6.0.2",
"expo-file-system": "~17.0.1",
"expo-image": "~1.13.0", "expo-image": "~1.13.0",
"expo-image-picker": "~15.0.7", "expo-image-picker": "~15.0.7",
"expo-linking": "~6.3.1", "expo-linking": "~6.3.1",
@@ -31,6 +33,7 @@
"expo-updates": "~0.25.26", "expo-updates": "~0.25.26",
"i18n-js": "^4.2.0", "i18n-js": "^4.2.0",
"moment": "^2.29.1", "moment": "^2.29.1",
"posthog-react-native": "^3.7.0",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",
"react-native": "0.74.5", "react-native": "0.74.5",
@@ -12749,6 +12752,51 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz", "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
}, },
"node_modules/posthog-react-native": {
"version": "3.7.0",
"resolved": "https://registry.npmjs.org/posthog-react-native/-/posthog-react-native-3.7.0.tgz",
"integrity": "sha512-iPQfYZvujIj81dtDP2lX09PImFQb9Ue/XGLupXrX9iIusTxTtOtN0TZdVhNBFpgY000m0H7lDqP7D32ui7grWw==",
"peerDependencies": {
"@react-native-async-storage/async-storage": ">=1.0.0",
"@react-navigation/native": ">= 5.0.10",
"expo-application": ">= 4.0.0",
"expo-device": ">= 4.0.0",
"expo-file-system": ">= 13.0.0",
"expo-localization": ">= 11.0.0",
"posthog-react-native-session-replay": "^0.1",
"react-native-device-info": ">= 10.0.0",
"react-native-navigation": ">=6.0.0"
},
"peerDependenciesMeta": {
"@react-native-async-storage/async-storage": {
"optional": true
},
"@react-navigation/native": {
"optional": true
},
"expo-application": {
"optional": true
},
"expo-device": {
"optional": true
},
"expo-file-system": {
"optional": true
},
"expo-localization": {
"optional": true
},
"posthog-react-native-session-replay": {
"optional": true
},
"react-native-device-info": {
"optional": true
},
"react-native-navigation": {
"optional": true
}
}
},
"node_modules/pretty-bytes": { "node_modules/pretty-bytes": {
"version": "5.6.0", "version": "5.6.0",
"resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz",

View File

@@ -10,6 +10,7 @@
"eject": "expo eject" "eject": "expo eject"
}, },
"dependencies": { "dependencies": {
"@expo/metro-config": "~0.18.11",
"@react-native-async-storage/async-storage": "1.23.1", "@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/netinfo": "11.3.1", "@react-native-community/netinfo": "11.3.1",
"@react-navigation/bottom-tabs": "^6.2.0", "@react-navigation/bottom-tabs": "^6.2.0",
@@ -17,17 +18,24 @@
"@react-navigation/native-stack": "^6.5.0", "@react-navigation/native-stack": "^6.5.0",
"assert": "^2.0.0", "assert": "^2.0.0",
"expo": "^51.0.0", "expo": "^51.0.0",
"expo-application": "~5.9.1",
"expo-asset": "~10.0.10",
"expo-av": "~14.0.7", "expo-av": "~14.0.7",
"expo-dev-client": "~4.0.27", "expo-dev-client": "~4.0.27",
"expo-device": "~6.0.2", "expo-device": "~6.0.2",
"expo-file-system": "~17.0.1",
"expo-image": "~1.13.0",
"expo-image-picker": "~15.0.7", "expo-image-picker": "~15.0.7",
"expo-linking": "~6.3.1", "expo-linking": "~6.3.1",
"expo-localization": "~15.0.3", "expo-localization": "~15.0.3",
"expo-media-library": "~16.0.5",
"expo-notifications": "~0.28.18", "expo-notifications": "~0.28.18",
"expo-sharing": "~12.0.1",
"expo-status-bar": "~1.12.1", "expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.26", "expo-updates": "~0.25.26",
"i18n-js": "^4.2.0", "i18n-js": "^4.2.0",
"moment": "^2.29.1", "moment": "^2.29.1",
"posthog-react-native": "^3.7.0",
"react": "18.2.0", "react": "18.2.0",
"react-dom": "18.2.0", "react-dom": "18.2.0",
"react-native": "0.74.5", "react-native": "0.74.5",
@@ -39,12 +47,7 @@
"react-native-vector-icons": "^9.1.0", "react-native-vector-icons": "^9.1.0",
"react-native-web": "~0.19.10", "react-native-web": "~0.19.10",
"react-native-webview": "13.8.6", "react-native-webview": "13.8.6",
"valtio": "^1.4.0", "valtio": "^1.4.0"
"@expo/metro-config": "~0.18.11",
"expo-image": "~1.13.0",
"expo-media-library": "~16.0.5",
"expo-sharing": "~12.0.1",
"expo-asset": "~10.0.10"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.24.0" "@babel/core": "^7.24.0"