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 |
The AEM DataLayer is available as a downloadable AEM Package and is easy to install and incorporate into your project.
The steps to install and configure the AEM DataLayer are:
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:
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!