mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🎨 Reused attribution for embeddable signup forms on own site
fixes https://github.com/TryGhost/Team/issues/3473 When a signup happens via the embeddable signup form on your own site, we'll use the default attribution, so it indistinguishable from a signup via Portal.
This commit is contained in:
parent
998708c81a
commit
4da658e72a
@ -869,6 +869,7 @@ export const transformApiTiersData = ({tiers}) => {
|
||||
|
||||
/**
|
||||
* Returns the member attribution URL history, which is stored in localStorage, if there is any.
|
||||
* @warning If you make changes here, please also update the one in signup-form!
|
||||
* @returns {Object[]|undefined}
|
||||
*/
|
||||
export function getUrlHistory() {
|
||||
|
@ -19,7 +19,7 @@ export const setupGhostApi = ({siteUrl}: {siteUrl: string}) => {
|
||||
email,
|
||||
emailType: 'signup',
|
||||
labels,
|
||||
urlHistory: getUrlHistory()
|
||||
urlHistory: getUrlHistory({siteUrl})
|
||||
});
|
||||
|
||||
const response = await fetch(url, {
|
||||
|
@ -13,7 +13,46 @@ export function isMinimal(options: SignupFormOptions): boolean {
|
||||
return !options.title;
|
||||
}
|
||||
|
||||
export function getUrlHistory(): URLHistory {
|
||||
/**
|
||||
* Get the URL history when the form is embedded on the site itself.
|
||||
*/
|
||||
export function getDefaultUrlHistory() {
|
||||
const STORAGE_KEY = 'ghost-history';
|
||||
|
||||
try {
|
||||
const historyString = localStorage.getItem(STORAGE_KEY);
|
||||
if (historyString) {
|
||||
const parsed = JSON.parse(historyString);
|
||||
|
||||
if (Array.isArray(parsed)) {
|
||||
return parsed;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Failed to access localStorage or something related to that.
|
||||
// Log a warning, as this shouldn't happen on a modern browser.
|
||||
|
||||
/* eslint-disable no-console */
|
||||
console.warn(`[Signup-Form] Failed to load member URL history:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
export function getUrlHistory({siteUrl}: {siteUrl: string}): URLHistory {
|
||||
// If we are embedded on the site itself, use the default attribution localStorage, just like Portal
|
||||
try {
|
||||
if (window.location.host === new URL(siteUrl).host) {
|
||||
const history = getDefaultUrlHistory();
|
||||
if (history) {
|
||||
return history;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Most likely an invalid siteUrl
|
||||
|
||||
/* eslint-disable no-console */
|
||||
console.warn(`[Signup-Form] Failed to load member URL history:`, error);
|
||||
}
|
||||
|
||||
const history: URLHistory = [];
|
||||
|
||||
// Href without query string
|
||||
|
Loading…
Reference in New Issue
Block a user