by Ursula Johnson

Created

April 18, 2017

Today’s guest post features the winner of our first AEM Rockstar Competition, Dan Klco of Perficient. Dan rocked Summit attendees with his presentation, so we asked him to share his DataLayer demo. In the coming weeks, we’ll share more AEM Rockstar posts and preview one semi-finalist’s IMMERSE presentation. Stay tuned!

Dan is an experienced Adobe Digital Marketing Technical Lead, Solution Architect, Consultant and Advisor. Through his career, he has become viewed as a valued thought leader in the industry, with solid skills in leading teams to implement successful digital marketing programs in the Adobe ecosystem. Dan is also a PMC Member of the Apache Sling project, which is the basis for Adobe’s Experience Manager product, this allows him unique insight into the AEM platform.

During the AEM Rockstar session at Adobe Summit, I had a chance to talk about Digital Marketing DataLayers in AEM. I discussed how this important design pattern can help simplify Adobe Experience Manager and Adobe Marketing Cloud integrations, and introduced AEM DataLayer, a new Open Source library for creating DataLayers in AEM.

I was thrilled to be awarded first prize for my presentation and would like to share some more with information with you about how to use the AEM DataLayer library on your project.

Step 1: Identifying Data to Track

In my talk, I discussed analyzing designs in the discovery phase, to identify what data you might need to capture for Digital Marketing. It is important to focus on the might rather than the need to ensure that your DataLayer will not require significant changes during the course of the implementation.

Given the page above, you may want to track some of the following information as an example:

 

Track Time

Scope

Information

Example

On Load

Page

Page URL

http://www.weretail.com/us/en/about-us.html

On Load

Page

Page Path

/us/en/about-us

On Load

Page

Site Section

about-us

On Load

Page

Region

us

On Load

Page

Language

en

On Load

Page

Page Title

About Us

On Load

Component

Video

/content/dam/we-retail/en/videos/Perficient-Digita-Agency-Reel.mp4

Event

Component

Video Play

Event

Component

Video Complete

Step 2: Configure AEM DataLayer

The AEM DataLayer is available as a downloadable AEM Package and is easy to install and incorporate into your project. Click here to watch my Spark video demo.

The steps to install and configure the AEM DataLayer are:

  1. Install the AEM DataLayer package
  2. Setup a Cloud Configuration for AEM DataLayer
  3. Add the Cloud Configuration on your site

Step 3: Add Your Custom DataLayer Code

To create your own DataLayer code, create a simple Bundle project and add the dependencies:

<dependency>

  <groupId>org.apache.sling</groupId>

  <artifactId>org.apache.sling.models.api</artifactId>

  <version>1.3.0</version>

  <scope>provided</scope>

</dependency>

<dependency>

  <groupId>com.perficient.aem</groupId>

  <artifactId>aem-datalayer.core</artifactId>

  <version>0.1.0</version>

</dependency>

 

You can then create Sling Model classes implementing the ComponentDataElement interface:

 

@Model(adaptables = Resource.class, resourceType = {"myapp/components/myresource" }, adapters = ComponentDataElement.class)
public class CustomDataElement implements ComponentDataElement {

For every class, you will need to specify the annotation parameters “resourceType” and “adapters”. You can specify any number of resource types, and when AEM encounters a resource of the type specified, it will call your Sling Model.

The WeRetail Reference project contains a number of examples ComponentDataElement classes you can use as a base for your custom implementations. For example, if you wanted to track the video displayed in every instance of the video component you scoped in Step 1, you could create a class like the one below:

/*
*  Copyright 2017 - Perficient
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.perficient.aem.weretail.datalayer;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.models.annotations.Model;

import com.perficient.aem.datalayer.api.Component;
import com.perficient.aem.datalayer.api.ComponentDataElement;
import com.perficient.aem.datalayer.api.DataLayer;

/**
* Adds in the video details for the AEM Mobile Video component into the
* AEMDataLayer
*
* @author danklco
*/
@Model(adaptables = Resource.class, resourceType = {
"mobileapps/components/mobilevideo" }, adapters = ComponentDataElement.class)
public class MobileVideoComponent implements ComponentDataElement {

private final Resource resource;

public MobileVideoComponent(Resource resource) {
this.resource = resource;
}

@Override
public void updateDataLayer(DataLayer dataLayer) {

Component component = new Component();
component.getComponentInfo().setComponentID(resource.getPath());

ValueMap properties = resource.getValueMap();

component.addAttribute("video", properties.get("fileReference", String.class));

dataLayer.addComponent(component);
}

}
This Gist brought to you by gist-it.view rawweretail-reference/src/main/java/com/perficient/aem/weretail/datalayer/MobileVideoComponent.java

Further Support

If you have any questions or comments about the AEM DataLayer, please open an issue on GitHub or message me on Twitter at @klcodanr. As the library matures, I will be building out more documentation and use cases on GitHub so please keep tuned!