mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added sending of events when clicking or subscribing to a recommendation
fixes https://github.com/TryGhost/Product/issues/3855
This commit is contained in:
parent
82079c1dc5
commit
e3347827ca
3 changed files with 49 additions and 4 deletions
|
@ -501,6 +501,22 @@ async function oneClickSubscribe({data: {siteUrl}, state}) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function trackRecommendationClicked({data: {recommendationId}, api}) {
|
||||||
|
api.recommendations.trackClicked({
|
||||||
|
recommendationId
|
||||||
|
});
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function trackRecommendationSubscribed({data: {recommendationId}, api}) {
|
||||||
|
api.recommendations.trackSubscribed({
|
||||||
|
recommendationId
|
||||||
|
});
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
const Actions = {
|
const Actions = {
|
||||||
togglePopup,
|
togglePopup,
|
||||||
openPopup,
|
openPopup,
|
||||||
|
@ -524,7 +540,9 @@ const Actions = {
|
||||||
updateNewsletterPreference,
|
updateNewsletterPreference,
|
||||||
showPopupNotification,
|
showPopupNotification,
|
||||||
removeEmailFromSuppressionList,
|
removeEmailFromSuppressionList,
|
||||||
oneClickSubscribe
|
oneClickSubscribe,
|
||||||
|
trackRecommendationClicked,
|
||||||
|
trackRecommendationSubscribed
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Handle actions in the App, returns updated state */
|
/** Handle actions in the App, returns updated state */
|
||||||
|
|
|
@ -74,7 +74,7 @@ export const RecommendationsPageStyles = `
|
||||||
.gh-portal-recommendation-item .gh-portal-list-detail:hover .gh-portal-recommendation-arrow-icon {
|
.gh-portal-recommendation-item .gh-portal-list-detail:hover .gh-portal-recommendation-arrow-icon {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gh-portal-recommendation-subscribed {
|
.gh-portal-recommendation-subscribed {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -155,6 +155,7 @@ const RecommendationItem = (recommendation) => {
|
||||||
const {title, url, reason, favicon, one_click_subscribe: oneClickSubscribe, featured_image: featuredImage} = recommendation;
|
const {title, url, reason, favicon, one_click_subscribe: oneClickSubscribe, featured_image: featuredImage} = recommendation;
|
||||||
const allowOneClickSubscribe = member && oneClickSubscribe;
|
const allowOneClickSubscribe = member && oneClickSubscribe;
|
||||||
const [subscribed, setSubscribed] = useState(false);
|
const [subscribed, setSubscribed] = useState(false);
|
||||||
|
const [clicked, setClicked] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const outboundLinkTagging = site.outbound_link_tagging ?? false;
|
const outboundLinkTagging = site.outbound_link_tagging ?? false;
|
||||||
|
|
||||||
|
@ -179,7 +180,12 @@ const RecommendationItem = (recommendation) => {
|
||||||
const visitHandler = useCallback(() => {
|
const visitHandler = useCallback(() => {
|
||||||
// Open url in a new tab
|
// Open url in a new tab
|
||||||
openTab(refUrl);
|
openTab(refUrl);
|
||||||
}, [refUrl]);
|
|
||||||
|
if (!clicked) {
|
||||||
|
onAction('trackRecommendationClicked', {recommendationId: recommendation.id});
|
||||||
|
setClicked(true);
|
||||||
|
}
|
||||||
|
}, [refUrl, recommendation.id, clicked]);
|
||||||
|
|
||||||
const oneClickSubscribeHandler = useCallback(async () => {
|
const oneClickSubscribeHandler = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -188,6 +194,10 @@ const RecommendationItem = (recommendation) => {
|
||||||
siteUrl: url,
|
siteUrl: url,
|
||||||
throwErrors: true
|
throwErrors: true
|
||||||
});
|
});
|
||||||
|
if (!clicked) {
|
||||||
|
onAction('trackRecommendationSubscribed', {recommendationId: recommendation.id});
|
||||||
|
setClicked(true);
|
||||||
|
}
|
||||||
setSubscribed(true);
|
setSubscribed(true);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
// Open portal signup page
|
// Open portal signup page
|
||||||
|
@ -195,9 +205,14 @@ const RecommendationItem = (recommendation) => {
|
||||||
|
|
||||||
// Trigger a visit
|
// Trigger a visit
|
||||||
openTab(signupUrl);
|
openTab(signupUrl);
|
||||||
|
|
||||||
|
if (!clicked) {
|
||||||
|
onAction('trackRecommendationClicked', {recommendationId: recommendation.id});
|
||||||
|
setClicked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, [setSubscribed, url, refUrl]);
|
}, [setSubscribed, url, refUrl, recommendation.id, clicked]);
|
||||||
|
|
||||||
const clickHandler = useCallback((e) => {
|
const clickHandler = useCallback((e) => {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
|
|
@ -163,6 +163,18 @@ function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
api.recommendations = {
|
||||||
|
trackClicked({recommendationId}) {
|
||||||
|
let url = endpointFor({type: 'members', resource: 'recommendations/' + recommendationId + '/clicked'});
|
||||||
|
navigator.sendBeacon(url);
|
||||||
|
},
|
||||||
|
|
||||||
|
trackSubscribed({recommendationId}) {
|
||||||
|
let url = endpointFor({type: 'members', resource: 'recommendations/' + recommendationId + '/subscribed'});
|
||||||
|
navigator.sendBeacon(url);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
api.member = {
|
api.member = {
|
||||||
identity() {
|
identity() {
|
||||||
const url = endpointFor({type: 'members', resource: 'session'});
|
const url = endpointFor({type: 'members', resource: 'session'});
|
||||||
|
|
Loading…
Add table
Reference in a new issue