For many actions on the page, tracking should not be treated like a page view. In this video, you will learn how to code a link tracking beacon to Analytics, if you are not using a tag manager (like Adobe Experience Platform Launch). See the code, as well as learning an important tip.
There are two functions that send data into Adobe Analytics:
In this video, we show you how to code a custom link hit when you are NOT using a tag manager like Adobe Experience Platform Launch. We recommend that you use Experience Platform Launch, our best-practice recommendation for implementation. However, if you need to code in an
s.tl(), here’s how to do it.
Hey everybody, this is Doug. In this video I wanna show you how to do custom link tracking on your site, if you are not using a tag manager like Adobe Launch. So, you just need to do it in the code and I wanna show you how to do that in this video. So first of all, really, even if you are using Launch, it’s all gonna be about this function called s.tl, which is short for track link. This is the function that you’ll want to call and again, we’re gonna talk about non tag managers in this video. So I have coded a couple of links into a page over here, little test page. So I have a link here that is pretending that we’re gonna share something on Facebook, and then just another random link and I’ll show you basically what those look like here in a second. But the main thing is that we’re gonna set some variables and then we are going to call this s.tl function for track link. Now I might also just take a moment and say, if you are tracking links on your site, please make sure that you have thought this through and that you are not basing the success of your site on link clicks. We can definitely track the clicks on links, but we really want to see how that leads to other success on our site. Not just basing the success of our site on people click click click click clicking around. Okay, so anyway, get off my soapbox for a minute there. Next, we can look at the format of this s.tl function that you’re gonna send in, so you can see it here. We’re gonna send in a this, and we’re gonna send in a link type and a link name. And then we got a couple of 'em over here that we’re not gonna talk about today 'cause they are not used very often and they are optional. But we definitely are gonna use these first three right here. You can see that the link type value, that’s the one right here in the middle, is gonna be either a d for downloads, an e for exit links, or an o for custom links. And the this moniker will stay as is, and then we will put in a link name. And there are a couple other things that we’re gonna need to do, in order to make this work, in fact, let me click over to this other documentation page, and you’ll see that we’re gonna have to set something called linkTrackVars, and linkTrackEvents. And so, you can go through the documentation here and I recommend that you do. Some really good information here, documentation on s.tl, and these link tracking hits that you’re sending in. So I do recommend that you go through all this documentation but I did want to just quickly show you how it works. And let me go ahead and switch over to a text editor. We have some links here, you can see there’s some text up there, anyway, here are the links. So we have this one link that says, click here to share on Facebook, and another one that is just another link, and I’ll get to that one in a minute and why I’ve done it this way. Basically though, here is how you’re gonna set this up. You are gonna set it up by setting linkTrackVars, potentially linkTrackEvents, and then setting some variables and then calling s.tl. Now you don’t have to set any variables, but let me just say, if you are going to set any additional variables, which you probably are in a lot of cases, then you need to jump through a couple of hoops here. These are our linkTrackVars and linkTrackEvents hoops. So, basically you need to tell us, what you’re gonna set, with these two, and then you can set them right here, okay? So if you’re going to set any variables with a custom link, with s.tl, you have to tell s.linkTrackVars, which variables you are going to set. So you can see that it is, events, now, you don’t put the object name, s, so you’re gonna put events, eVar2, and prop2.
We’re gonna set those three, events, eVar2, prop2. Now if you’re going to set an event, then you also need to set linkTrackEvents, and tell us which event you are going to set, right there. Okay? So again, you’re gonna say, here’s what I’m gonna set, pay attention to these ones, and then you set them, and then you send it in, okay? And that is how you are using s.tl, and I’ll get to this other part below there in a second. But that’s the main thing. Now that also means, of course, that you can do this any way you want. This can be on the on click, it can be triggered however you want, at the end of the day, you are just making sure that you fire these things, and sending them in, okay? So you can see here that I have, by the way, put them on different lines, and they’re all part of this on click right here. This also means of course that I am nesting my quotes, single quotes and double quotes, so make sure that you don’t mess that up, that’s easy to make a mistake on. And in any case, we can also, looks like we can also take s.events, and we can merge these two together, right? So I can take this, and just maybe put it right here.
Here is the sample code used on the custom link in the video:
<a href="#" onclick=" s.linkTrackVars='events,eVar2,prop2'; s.linkTrackEvents=s.events='event2'; s.eVar2='facebook share'; s.prop2='facebook share'; s.tl(this,'o','Social Share'); s.manageVars('clearVars',s.linkTrackVars,1);"> Click here to share on FaceBook </a>