-
-
Save yuhui/6657fda3c49db8fba5eb7934566f683a to your computer and use it in GitHub Desktop.
Adobe Web SDK: improve click data collection by not tracking "other" links automatically, and using the link URL as the link name for "download" and "exit" links.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Modify content.xdm or content.data as necessary. There is no need to wrap the | |
// code in a function or return a value. For example: | |
// content.xdm.web.webPageDetails.name = "Checkout"; | |
var sendHit = true; | |
switch (content.xdm.eventType) { | |
case 'web.webpagedetails.pageViews': | |
// nothing to do here | |
// keep calm and carry on | |
break; | |
case 'web.webinteraction.linkClicks': | |
if (content.xdm.web && content.xdm.web.webInteraction) { | |
// Click data collection is great for automatically tracking clicks on links but it has room for improvement: | |
// 1. Don't collect click data automatically for "other" links (i.e. custom links). | |
// 2. Replace the link name with the link URL for "download" and "exit" links. | |
if (content.xdm.web.webInteraction.name === 'Link Click') { | |
switch (content.xdm.web.webInteraction.type) { | |
case 'other': | |
// ** DO NOT track "other" web.webInteraction.type ** | |
// For navigational links, explicit Custom Links should be tracked instead. | |
_satellite.logger.debug('abort Web SDK for automatic Link Click tracking!'); | |
sendHit = false; | |
break; | |
case 'download': | |
case 'exit': | |
// ** DELETE web.webInteraction.name when web.webInteraction.type is "download" or "exit" ** | |
// This is for Adobe Analytics' benefit, so that the resulting Download Links and Exit Links dimensions | |
// get populated with the download/exit links' URLs, instead of the default "Link Click". | |
_satellite.logger.debug('delete link name for Web SDK for automatic Download/Exit Link Click tracking!'); | |
delete content.xdm.web.webInteraction.name; | |
break; | |
} | |
} | |
} | |
break; | |
default: | |
if (content.xdm.web && content.xdm.web.webPageDetails) { | |
if (content.xdm.web.webPageDetails.pageViews && (!content.xdm.web.webPageDetails.pageViews.value || content.xdm.web.webPageDetails.pageViews.value === 0)) { | |
// A page is being tracked when there was no intention to, e.g. when getting personalisation data from Target | |
// but this causes the web.webPageDetails.pageViews.value to be unset or 0 | |
// so change this to a Custom Link | |
// DON'T drop the hit! Otherwise dependent executions, e.g. getting Target personalisation data, will fail. | |
content.xdm.web.webInteraction = content.xdm.web.webInteraction || {}; | |
content.xdm.web.webInteraction.type = 'other'; | |
content.xdm.web.webInteraction.name = 'ExperienceEvent type: ' + (content.xdm.eventType || 'no Web SDK event type'); | |
} | |
} | |
break; | |
} | |
return sendHit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment