Vous consultez actuellement l'aide de la version:
The default set of Cloud Services can be extended with custom Cloud Service types. This allows you to inject custom markup into the page in a structured fashion. This will be primarily of use for 3rd party analytics providers, for example Google Analytics, Chartbeat, etc.
Cloud Services are inherited from parent pages to child pages with the ability to break the inheritance at any level.
Remarque :
This step-by-step guide for creating a new Cloud Service is an example using Google Analytics. Everything might not apply to your use case.
-
Create a new file named content.jsp under /apps/acs/analytics/components/googleanalyticspage, with the following content:
<%@page contentType="text/html" pageEncoding="utf-8"%><% %><%@include file="/libs/foundation/global.jsp"%><div> <div> <h3>Google Analytics Settings</h3> <ul> <li><div class="li-bullet"><strong>accountID: </strong><br><%= xssAPI.encodeForHTML(properties.get("accountID", "")) %></div></li> </ul> </div>
-
Create a new node under/apps/acs/analytics/components/googleanalyticspage/dialog/items/items/tab1:
- Name: items
- Type: nt:unstructured
- Properties:
- Name:fieldLabel
- Type: String
- Value: Account ID
- Name: fieldDescription
- Type: String
- Value: The account ID assigned by Google. Usually in the form UA-NNNNNN-N
- Name: name
- Type: String
- Value: ./accountID
- Name: validateOnBlur
- Type: String
- Value: true
- Name: xtype
- Type: String
- Value: textfield
-
Create a new template under /apps/acs/analytics/templates/:
- with Resource Type = acs/analytics/components/googleanalyticspage
- with Label =googleanalytics
- with Title = Google Analytics Configuration
- with allowedPath = /etc/cloudservices/googleanalytics(/.*)?
- with allowedChildren = /apps/acs/analytics/templates/googleanalytics
- with sling:resourceSuperType = cq/cloudserviceconfigs/templates/configpage (on template node, not the jcr:content node)
- with cq:designPath = /etc/designs/cloudservices/googleanalytics (on jcr:content)
-
Create new component: /apps/acs/analytics/components/googleanalytics.
Add the following content to googleanalytics.jsp:
<%@page import="org.apache.sling.api.resource.Resource, org.apache.sling.api.resource.ValueMap, org.apache.sling.api.resource.ResourceUtil, com.day.cq.wcm.webservicesupport.Configuration, com.day.cq.wcm.webservicesupport.ConfigurationManager" %> <%@include file="/libs/foundation/global.jsp" %><% String[] services = pageProperties.getInherited("cq:cloudserviceconfigs", new String[]{}); ConfigurationManager cfgMgr = resource.getResourceResolver().adaptTo(ConfigurationManager.class); if(cfgMgr != null) { String accountID = null; Configuration cfg = cfgMgr.getConfiguration("googleanalytics", services); if(cfg != null) { accountID = cfg.get("accountID", null); } if(accountID != null) { %> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '<%= accountID %>']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script><% } } %>