Expand my Community achievements bar.

SOLVED

How to pass custom event with exit link in DTM

Avatar

Level 2

Hi

I have a use case where I want to pass custom event along with out of the box exit link which is getting tracked. E.g. I want 'event1' to be populated with exit link call along with 'eVar3'

All the configuration in DTM via DTM UI like I have 'Track outbound links' option checked and I have my filters specified in UI which are working as expected.

Any pointers?

'Thanks

Pankaj

1 Accepted Solution

Avatar

Correct answer by
Level 9

In response to @aseelund's post:

Creating an Event Based Rule instead of adding code in the Adobe Analytics Tool config is a viable option, however, I do not recommend using _satellite.isOutboundLink(), for the following reasons:

  • _satellite.isOutboundLink() is not on the list of methods marked as public facing. To be fair, the chances of Adobe updating this function at this point are pretty slim, but it's still generally bad practice to go against the docs. 
  • Adobe Analytics Tool > Link Tracking (s.linkInternalFilters) performs a substring ("contains") match against the target URL (which may or may not include the query string, depending on whether or not you enable "keep URL parameters" (s.linkLeaveQueryString). Meanwhile _satellite.isOutboundLink() performs an end of string ("ends with") comparison against the target URL's hostname. Because matching methodologies do not align, you may get unexpected results!
  • _satellite.isOutboundLink()matches against _satellite.settings.domainList (DTM property level config), which may or may not line up with the domain(s) you may normally want to specify in Adobe Analytics Tool > Link Tracking (s.linkInternalFilters). One common example is if you have subdomains on your root .mysite.com domain that you may want to consider as exit links. Or if you have a lot of domains and just want to specify a common value e.g. "mysite". Or, (not) matching start of string values, such as "javascript:" or "mailto:"

So, if you want to go the Event Based Rule route, you should skip the bit about _satellite.isOutboundLink() and instead modify the Property = Value regex condition to include domains you do not want to track as exit links. 

For example:

Property: href

Value:  ^(?!.*(tel:|javascript:|mailto:|\.mysite\.com)).*

Though, depending on how long your internal domain list is (or if you want to avoid regex), you may want to instead do a custom code condition with something like this:

// list of values to match against to NOT trigger exit link tracking

// note that this is a substring match, which is how Adobe Analytics linkInternalFilters works

var internal = [

  'tel:',

  'javascript:',

  'mailto:',

  '.mysite.com'

];

var href=this&&this.href||'';

for (var d=0,l=internal.length;d<l;d++) {

  if ( ~href.indexOf(internal[d]) ) return false;

}

return true;

View solution in original post

4 Replies

Avatar

Level 9

DTM does not have a built-in configuration section for this, but you can do this with javascript code.

First, navigate to Overview > Adobe Analytics > Tool Config (gear icon)

1373320_pastedImage_0.png

Next, scroll down to Customize Page Code and click Open Editor

1373318_pastedImage_7.png

Next, add the following code in the code box:

s.usePlugins = true;

s.doPlugins = function(s) {

    /* custom exit link tracking */

    if (s.linkObject && s.linkURL && s.linkType == 'e') {

        /* set variables to pop */

        s.events = "event1";

        // example: set s.eVar to target URL

        s.eVar3 = s.linkURL;

        /* make sure you register your events and eVars to linkTrackVars/linkTrackEvents! */

        s.linkTrackVars = "events,eVar3";

        s.linkTrackEvents = "event1";

    } // end custom exit link tracking

} // end doPlugins

This code snippet enables and defines a callback function that gets called when a link is clicked (doPlugins gets called for a number of other scenarios, as well). The "custom exit link tracking" snippet within doPlugins is wrapped in a condition to qualify that a visitor just clicked an exit link

s.linkObject - A reference to the clicked html element on the page. It is good to check for the existence of this for standard html links on a page. However, you may need to remove this if you have custom code that triggers exit link tracking in other scenarios (uncommon).

s.linkURL - A reference to the clicked html element's href attribute.  Same as above: you may need to omit this if you have custom code that manually triggers exit link tracking.

s.linkType - If a link (<a> element) was clicked, this indicates what type of link was clicked, based on your Link Tracking configuration. For links determined to be exit links, this value should be "e".  Unlike the other two variables in the condition, this one should not be omitted.  If you have other code that artificially triggers exit link tracking (e.g. something that ultimately makes a s.tl(true,'e','some value'); call, s.linkType should still have a value for you to check for (the 2nd arg in the s.tl call (even if it is DTM internally calling it from e.g. some Event Based Rule or Direct Call Rule vs. you directly making a s.tl call yourself))

Note: By default, Adobe Analytics does not wipe variables between s.t or s.tl calls on a given page, so they are effectively "cached" on a given page (as long as the "s" object exists on the page).  However, you may have variables set on a page view that you do not want to "bleed over" to subsequent tracking calls on the page. To solve for this, there are two variables that you must "register" your events and variables you want to track in your link tracking (s.tl) call.  Variables/events not "registered" to these variables are ignored and not included in the link tracking (s.tl) call.

s.linkTrackVars - A comma delimited list of the variables you want to include for link tracking. Note that the "s." namespace should not be included; only the variable name itself.

s.linkTrackEvents - A comma delimited list of the events you want to include for link tracking. In your scenario, this should be the same value as your s.events variable (sidenote: this isn't relevant to your scenario, but note you should only list the actual event[n] value in linkTrackEvents, not serialized/currency/numeric values added to them in s.events).

Also Note: This example assumes you have a basic implementation using default "s" object and do not have an existing s.doPlugins function defined.  Make sure to alter your code accordingly!  For example, you cannot have more than one s.doPlugins defined, so if it is already defined, add the exit link code to it.

Avatar

Level 3

We use a custom event rule instead of the out of the box handling.

1) disable (uncheck) the OotB adobe config

2) new event rule

3) condition must meet (_satellite.isOutboundLink === true)

(note in the condition, we create a var name %outboundLinkTarget% to collect the href value into an eVar)

4) set events, evars and props

1375757_pastedImage_0.png

[... more conditions ...]

______ Analytics ______

1375758_pastedImage_1.png

Avatar

Correct answer by
Level 9

In response to @aseelund's post:

Creating an Event Based Rule instead of adding code in the Adobe Analytics Tool config is a viable option, however, I do not recommend using _satellite.isOutboundLink(), for the following reasons:

  • _satellite.isOutboundLink() is not on the list of methods marked as public facing. To be fair, the chances of Adobe updating this function at this point are pretty slim, but it's still generally bad practice to go against the docs. 
  • Adobe Analytics Tool > Link Tracking (s.linkInternalFilters) performs a substring ("contains") match against the target URL (which may or may not include the query string, depending on whether or not you enable "keep URL parameters" (s.linkLeaveQueryString). Meanwhile _satellite.isOutboundLink() performs an end of string ("ends with") comparison against the target URL's hostname. Because matching methodologies do not align, you may get unexpected results!
  • _satellite.isOutboundLink()matches against _satellite.settings.domainList (DTM property level config), which may or may not line up with the domain(s) you may normally want to specify in Adobe Analytics Tool > Link Tracking (s.linkInternalFilters). One common example is if you have subdomains on your root .mysite.com domain that you may want to consider as exit links. Or if you have a lot of domains and just want to specify a common value e.g. "mysite". Or, (not) matching start of string values, such as "javascript:" or "mailto:"

So, if you want to go the Event Based Rule route, you should skip the bit about _satellite.isOutboundLink() and instead modify the Property = Value regex condition to include domains you do not want to track as exit links. 

For example:

Property: href

Value:  ^(?!.*(tel:|javascript:|mailto:|\.mysite\.com)).*

Though, depending on how long your internal domain list is (or if you want to avoid regex), you may want to instead do a custom code condition with something like this:

// list of values to match against to NOT trigger exit link tracking

// note that this is a substring match, which is how Adobe Analytics linkInternalFilters works

var internal = [

  'tel:',

  'javascript:',

  'mailto:',

  '.mysite.com'

];

var href=this&&this.href||'';

for (var d=0,l=internal.length;d<l;d++) {

  if ( ~href.indexOf(internal[d]) ) return false;

}

return true;

Avatar

Level 1

Thanks for all the very fast replies.

I think my predicament may have been slightly misunderstood.  We are using isOutboundLink in DTM already but we are moving to Launch and it appears that Launch doesn't recognize it.

So we are looking for a way to do something similar in Launch.

I will look further into JoshD's response but if anyone has other ideas I am open.

Thanks again.