META-INF.resources.dynamic_include.top_head.jsp Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.segments.experiment.web
Show all versions of com.liferay.segments.experiment.web
Liferay Segments Experiment Web
<%--
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
--%>
<%@ include file="/init.jsp" %>
<%
SegmentsExperiment segmentsExperiment = (SegmentsExperiment)request.getAttribute(SegmentsExperimentWebKeys.SEGMENTS_EXPERIMENT);
%>
var elements = [];
var targetableCollectionElements = document.querySelectorAll(
'[id^=analytics-targetable-collection]'
);
if (targetableCollectionElements.length) {
targetableCollectionElements.forEach((element, index) => {
if ('#' + element.id === '<%= segmentsExperiment.getGoalTarget() %>') {
elements.push(element);
}
});
}
else {
elements.push(
document.querySelector('<%= segmentsExperiment.getGoalTarget() %>')
);
}
if (elements.length) {
elements.forEach((element) => {
element.addEventListener('click', () => {
if (window.Analytics) {
Analytics.send('ctaClicked', 'Page', {elementId: element.id});
}
});
});
}