Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /home/claqxcrl/www/wp-content/plugins/extendify/src/Recommendations/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/claqxcrl/www/wp-content/plugins/extendify/src/Recommendations/utils/record-activity.js
import { INSIGHTS_HOST } from '@constants';
import {
	selectInstalledPlugins,
	selectActivePlugins,
	selectAllRecommendations,
} from '@recommendations/selectors/plugin-search';
import { usePluginSearchStore } from '@recommendations/state/plugin-search';
import { objectFromKeys } from '@recommendations/utils/object-from-keys';

const { extSharedData, extRecommendationsData } = window;

const showPartnerBranding = !!(
	extRecommendationsData?.showPartnerBranding && extSharedData?.partnerLogo
);

const stores = {
	'plugin-search': usePluginSearchStore,
};

const validSlots = Object.keys(stores);

export const recordActivity = ({ slot, event, product }) => {
	if (!event || !validSlots.includes(slot)) {
		return;
	}

	const state = stores[slot].getState();

	const installedPlugins = selectInstalledPlugins(state);
	const activePlugins = selectActivePlugins(state);
	const recommendations = selectAllRecommendations(state).map(
		(recommendation) =>
			objectFromKeys(recommendation, [
				'slug',
				'title',
				'description',
				'ctaContent',
				'ctaType',
				'triggerContent',
				'triggerType',
			]),
	);
	const recommendation = recommendations.find(
		(recommendation) => recommendation.slug === product,
	)?.slug;

	const payload = {
		event: event,
		timestamp: new Date().toISOString(),
		slot,
		recommendation,
		recommendations,
		recommendationsLimit: state.recommendationsLimit,
		query: decodeURIComponent(state.query),
		searchResults: state.searchPlugins,
		searchResultsLimit: state.searchPluginsLimit,
		installedPlugins,
		activePlugins,
		partnerBrandingEnabled: showPartnerBranding,
		partnerId: extSharedData.partnerId,
		siteId: extSharedData.siteId,
		wpVersion: extSharedData.wpVersion,
		wpLocale: extSharedData.wpLanguage,
		extendifyVersion: extSharedData.version,
		devbuild: extSharedData.devbuild,
	};

	const controller = new AbortController();

	window.setTimeout(() => {
		controller.abort();
	}, 900);

	fetch(`${INSIGHTS_HOST}/api/v1/recommendations/activity`, {
		method: 'POST',
		headers: {
			Accept: 'application/json',
			'Content-Type': 'application/json',
			'X-Extendify-Site-ID': extSharedData.siteId,
		},
		signal: controller.signal,
		body: JSON.stringify(payload),
	}).catch(() => null);
};

ZeroDay Forums Mini