/** * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ package com.liferay.content.targeting.tracking.action.youtube; import com.liferay.content.targeting.analytics.util.AnalyticsUtil; import com.liferay.content.targeting.api.model.BaseTrackingAction; import com.liferay.content.targeting.api.model.TrackingAction; import com.liferay.content.targeting.model.TrackingActionInstance; import com.liferay.content.targeting.util.ContentTargetingContextUtil; import com.liferay.portal.kernel.language.LanguageUtil; import com.liferay.portal.kernel.util.ListUtil; import com.liferay.portal.kernel.util.StringPool; import java.util.List; import java.util.Locale; import java.util.Map; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; /** * @author Eduardo Garcia */ @Component(immediate = true, service = TrackingAction.class) public class YoutubeTrackingAction extends BaseTrackingAction { @Activate @Override public void activate() { super.activate(); } @Deactivate @Override public void deActivate() { super.deActivate(); } @Override public List<String> getEventTypes() { return ListUtil.fromArray(_EVENT_TYPES); } @Override public String getIcon() { return "icon-youtube"; } @Override public String getSummary( TrackingActionInstance trackingActionInstance, Locale locale) { String summary = LanguageUtil.format( locale, "tracking-action-x-in-youtube-x", new Object[] { trackingActionInstance.getEventType(), trackingActionInstance.getElementId() }); return summary; } @Override protected void populateContext( TrackingActionInstance trackingActionInstance, Map<String, Object> context, Map<String, String> values) { String alias = StringPool.BLANK; String elementId = StringPool.BLANK; String eventType = StringPool.BLANK; if (!values.isEmpty()) { alias = values.get("alias"); elementId = values.get("elementId"); eventType = values.get("eventType"); } else if (trackingActionInstance != null) { alias = trackingActionInstance.getAlias(); elementId = trackingActionInstance.getElementId(); eventType = trackingActionInstance.getEventType(); } context.put("alias", alias); context.put("elementId", elementId); context.put("eventType", eventType); context.put("eventTypes", getEventTypes()); long groupId = (Long)context.get("scopeGroupId"); boolean trackingYoutubeEnabled = AnalyticsUtil.isAnalyticsYoutubeEnabled(groupId); context.put("trackingYoutubeEnabled", trackingYoutubeEnabled); if (!trackingYoutubeEnabled) { ContentTargetingContextUtil.populateContextAnalyticsSettingsURLs( context); } } // See html/js/analytics/integrations/youtube_iframe.js in Analytics Hook private static final String[] _EVENT_TYPES = { "unstarted", "buffering", "playing", "paused", "ended"}; }