I constantly get this question, so I figured it would be good to write a quick post about it. The question is always a variation of "how do I get my Sitecatalyst s object within DTM?"

There are several ways to get the s object, but they are going to vary depending on the way you've done your implementation.

1) Managed as Custom

This is the most straightforward and will work inside any custom scripts on the Adobe Analytics tag in your rules. It will also work on the page and custom javascript snippets. However, the second option will ONLY work if your analytics was setup to be managed as "custom".

Why? When you tell DTM that you will manage the s code, you are saying anything goes, so it needs to run in the global scope. When you run a snippet in the global scope, and do your regular var s = s_gi(s_account), or similar, you're saying that this global s object should be created. Since that is fine and dandy, anywhere can access it just fine as "s". This is also why they make you specify the name of the s object when you are setting it up - so they can get a reference to it.

2) Managed by Adobe

Now, when you tell DTM to make the s code managed by Adobe - it does something completely different. It no longer runs in the global scope and the "s" object doesn't even exist as "s". Rather it is some localized scope with no actual name. If you try to reference "s" on the page - it may appear sometimes, but more often than not, it will just say "undefined". However, any Adobe Analytics "custom script" sections still allow you to reference "s". This is because it runs those custom sections, but creates a reference to the tool as "s" just for that script.

But what if I need the s object reference and it's managed by Adobe? Well...there are a couple ways:

  1. Inside the tool configuration's custom script section, make a reference to the s object. Something like window.s = s;. This will let you view the s object on the page. However, it is strongly recommended to NOT act upon the window.s object, as there is no promise that it will keep the same s object as the scope Adobe's managed code is using.
  2. Use the following snippet: var s = _satellite.getToolsByType('sc')[0].getS(). I've seen mixed results with this. Namely because it has to be run after the tool has been initialized. It also doesn't always return the proper scope. However, it does much better than #1 in many cases.

I will add a note that, if you are asking the last question, you are probably doing something incorrectly in your DTM implementation. Every correct implementation I've seen and done has no need to ever do these references. Namely, all your logic should be able to be handled via the custom script sections of the built-in Adobe tool.

Summary

Hopefully this quick post helps you understand how the s object is used and how to reference it! If you are running into further issues, or need a quick lookover your implementation, feel free to reach out to my consultancy for some additional help! InteliQuant