Skip to content

Instantly share code, notes, and snippets.

@jfkhoury
Last active July 3, 2024 23:16
Show Gist options
  • Select an option

  • Save jfkhoury/b390688267854c75d75245ed0c12253b to your computer and use it in GitHub Desktop.

Select an option

Save jfkhoury/b390688267854c75d75245ed0c12253b to your computer and use it in GitHub Desktop.
/**
* Default all events to `LinkClick`, unless the event is a Page View:
*
* NOTE: This script will only execute if the `web.webInteraction.type` was not already set.
*
* Here's what constitutes a Page View:
*
* 1. If the `Event Type` is: web.webpagedetails.pageViews
* 2. If the `Page View` metric XDM FieldGroup is populated: `xdm.web.webPageDetails.pageViews.value`
*
* Here's how this script transforms an event to `LinkClick`:
*
* 1. It sets the `xdm.web.webInteraction.type: "other"` field.
* 2. It sets the `xdm.web.webInteraction.name: "..."` field.
*
* The name is set as follows:
*
* 1. If the `Event Type` is `display` or `click; name becomes: `ADBE-A4T:display` or `ADBE-A4T:click`
* 2. Otherwise, the `name` is set as the `Event Type`.
*
* version: 1.0
*/
// This is a list of events we consider a page view:
// By default, this script considers "web.webpagedetails.pageViews" is a page view event type.
// Feel free to add other event types to this array if you decide to use a custom type as page view.
var pageViewEventTypes = ["web.webpagedetails.pageViews"];
function isWebInteractionTypeSet() {
try {
return Boolean(content.xdm.web.webInteraction.type);
} catch (ex) {
return false;
}
}
// This helper looks into the event type OR the page view metric to decide of the event is a page view.
function isPageViewEvent(eventType) {
var isPageViewEventType =
eventType && pageViewEventTypes.indexOf(eventType) !== -1;
var isPageViewMetricSet;
try {
isPageViewMetricSet = content.xdm.web.webPageDetails.pageViews.value > 0;
} catch (ex) {
isPageViewMetricSet = false;
}
return isPageViewEventType || isPageViewMetricSet;
}
function convertEventToLinkClick() {
var eventType = content.xdm.eventType;
if (!content.xdm.web) {
content.xdm.web = {};
}
if (!content.xdm.web.webInteraction) {
content.xdm.web.webInteraction = {};
}
content.xdm.web.webInteraction.type = "other";
content.xdm.web.webInteraction.name = "ExperienceEventType:" + (eventType || "NONE");
}
function shouldConvertEventToLinkClick(eventType) {
// We won't convert the event to link click if its type if considered a `Page View`.
// By default, "web.webpagedetails.pageViews" is considered a `Page View`.
if (isPageViewEvent(eventType)) {
return false;
}
if (!isWebInteractionTypeSet()) {
return true;
}
}
if (shouldConvertEventToLinkClick(content.xdm.eventType)) {
convertEventToLinkClick();
}
@cthae

cthae commented Jul 3, 2024

Copy link
Copy Markdown

Be very careful with this code. It will kill your Target personalization hits. You will not get the tests with alloy if you use the instance of alloy surfaced by Launch. And you DO want to use the Launch's instance of alloy because otherwise your a4t won't work, so there won't be any data on your tests in AA. Only in Target.

This whole code is a hotfix. I use it only because one of thos large agencies did another poor implementation of websdk, generating a whole bunch of rules nobody needs, each with it's own dedicated and fully defined separate dataelement. Can't just go through a hundred of XDM schemas and fix the pageview indicator in each. This code helps with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment