Downloads - extract file name and map within AppMeasurement SC Tag

Employee Emeritus
I am looking for a solution to extract the file name from the url or link_text and then map the file name to a prop. Example: http://spinside-dev.lfg.com/ourcompany/brandadverts/brandresctr/Documents/Stationery/E-Mail_Signatur... Ideally I would only capture "E-Mail_Signature.pdf" and map accordingly. I am not sure if it would be best to extract this from the URL or from the link_text. Thanks!
4 REPLIES 4

Downloads - extract file name and map within AppMeasurement SC Tag

Employee Emeritus
Hey Jim, The do_Plugins function gets called on download links so you can add some code to the do_plugins function. In my sandbox, I did something like this: if(s.linkType=="d"){ var ind = s.linkURL.lastIndexOf('/')+1; var val = s.linkURL.substring(ind); s.linkTrackVars = "eVar1,prop1"; s.pageName = val; s.eVar1 = s.prop1 = val; } Note: This code goes into the do_plugins function. This sets the pageName, eVar1 and prop1 to the name of the file. I set all these variable just to make sure you could pass eVars and props, but obviously not all are needed. This will work if the reference to your file is a url with slashes '/' as in your example. If you've got other ways files are referenced we may need to alter this just a bit. Hope this helps.

Downloads - extract file name and map within AppMeasurement SC Tag

Employee Emeritus
Hey Jared, We stopped using our Plugins and DoPlugins extensions after we made the switch the AppMeasurement for JavaScript tag. We were advised by our Adobe services folks that only certain plugins are supported. That being said, I attempted to add this to the extension and it caused the tag to fail. Could we somehow wrap something similar to this in a JS extension that would trigger on downloads?

Downloads - extract file name and map within AppMeasurement SC Tag

Employee Emeritus
Hey Jim, You are correct. Not all plugins are supported with the AppMeasurement Code, but the code above isn't using any plugins. So you should be safe. The only way to get this to work is to use the doPlugins section. Since the utag.link or utag.view function isn't getting triggered on click of download links, putting this code into a javascript extension, without the doPlugins function, won't work because the code will never get called. However, the SC library calls the doPlugins function automatically on click of downloads which is why this code has to be in there. This is what you can use in a JS Extension scoped to the AppMeasurement Tag: /* Plugin Config */ s.usePlugins=true function s_doPlugins(s) { if(s.linkType=="d"){ var ind = s.linkURL.lastIndexOf('/')+1; var val = s.linkURL.substring(ind); s.linkTrackVars = "eVar1,prop1"; s.pageName = val; s.eVar1 = s.prop1 = val; } } s.doPlugins=s_doPlugins That should do the trick, and since there aren't any plugins being used it should be safe from the unsupported plugins. Also, the "if" statement will only allow the code to run on download links. So it won't be running unnecessarily.

Downloads - extract file name and map within AppMeasurement SC Tag

Employee Emeritus
Jared....... You are the man! Thanks
Public