0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added new alpha analytics script for capturing events

refs https://github.com/TryGhost/Team/issues/1063
refs https://github.com/TryGhost/Team/issues/1062

Member activity is a labs alpha feature which aims at capturing member events for site owner if switched on. The event metadata captures the site page/post where the event originates from, and the post/page id is included as content of new ghost analytics meta tag.

This change sets up new analytics script in portal if analytics is switched on, and fires post/page view event when a valid analytics id is found.
This commit is contained in:
Rishabh 2021-09-20 15:11:54 +05:30
parent bfa91ee1ea
commit 1c40c211f5
2 changed files with 34 additions and 2 deletions

View file

@ -0,0 +1,22 @@
import setupGhostApi from './utils/api';
function sendEntryViewEvent({analyticsId, api}) {
if (analyticsId) {
api.analytics.pushEvent({
event_name: 'entry_view',
member_id: '',
member_status: '',
entry_id: analyticsId,
source_url: window.location.href
});
}
}
function setupAnalytics({siteUrl, analyticsId}) {
const GhostApi = setupGhostApi({siteUrl});
// Fire page/post view event
sendEntryViewEvent({analyticsId, api: GhostApi});
return {};
}
export default setupAnalytics;

View file

@ -2,6 +2,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import setupAnalytics from './analytics';
const ROOT_DIV_ID = 'ghost-portal-root';
@ -30,15 +31,24 @@ function handleTokenUrl() {
}
}
function setup() {
function setupAnalyticsScript({siteUrl}) {
const analyticsTag = document.querySelector('meta[name=ghost-analytics-id]');
const analyticsId = analyticsTag?.content;
if (siteUrl && analyticsTag) {
setupAnalytics({siteUrl, analyticsId});
}
}
function setup({siteUrl}) {
addRootDiv();
handleTokenUrl();
setupAnalyticsScript({siteUrl});
}
function init() {
const customSiteUrl = getSiteUrl();
const siteUrl = customSiteUrl || window.location.origin;
setup();
setup({siteUrl});
ReactDOM.render(
<React.StrictMode>
<App siteUrl={siteUrl} customSiteUrl={customSiteUrl} />