The Adobe Analytics media module is a fairly simple way to track generic video milestones. However, doing it in dtm can be tricky.
I wanted to write a quick post about this since I ran into several issues when it came to implementing the media module in dtm. You can follow Adobe's help guide for the most part, but the tricky piece comes when trying to integrate it into something like Youtube.
Basically, the media module uses a set of functions to determine steps in a player. An example might be "s.Media.open" to initialize the player. This is good since you have control over when these fire and can implement just about any video player with them. For my case, I had a youtube plugin built and put all the s.Media events in the right place.
Not to my surprise...the tracking didn't work. I've done this plugin many times on other platforms, but never in dtm - so was not surprised when it wasn't tracking. I kept getting an "s is not defined" error and "t.Media.open(...) is not a function" error. This became pretty frustrating, since I had the module in the right spot - was initializing properly, and I knew the youtube plugin part was working as expected. I tried everything I could think of, since this seems to point to a scoping issue.
The problem is with DTM and the poor integration it has with Analytics plugins and modules. The whole problem probably wouldn't exist if I was managing my own s code. However, as per Adobe's recommendations, I have it managed by them. This causes an s object to technically not even exist in a global scope, so something like s.Media.open is going to not even exist in many cases. I ended up having to do two things different to get this to work:
First: In my youtube plugin, I needed an "s" reference. This snippet from my other post helped with that: var s = _satellite.getToolsByType('sc').getS(); I just put this at the top of the state change for youtube and I now had a reference.
Second: I thought the first scoping issue might help, but it seemed the new error of the open/play/stop functions not being defined was strange. This had to be tied to the media module not initializing, even though I put everything correctly. To make a long story short, I knew the inner workings of the media module, so attempted changing this: s.loadModule('Media'); to this: s.Media = new AppMeasurement_Module_Media(s);.
Boom! s.Media now had all the missing functions that the built in stuff couldn't provide. I refreshed my page and every event started flowing perfectly. The biggest problem is the scoping. Adobe Analytics is built where the s code should be a global scope, whereas dtm is built to be all local scopes. This presents many problems - this module being one of them. The fix here essentially hacks their regular scoping to work in our favor.