Accessing app model

We’re trying to set up FullStory to record only users who have logged in. I was trying to include a script in the DOM header insertions for FullStory wrapped in a conditional based on the existence of a value in app.vars.userId, but this isn’t working. I also discovered that I can’t console log app.vars.userId, so it doesn’t seem to be accessible this way. How can I better accomplish this?

`if(app.vars.userId) {`
`window['_fs_debug'] = false;`
`window['_fs_host'] = '` `` `';`
`window['_fs_script'] = '` `` `';`
`window['_fs_org'] = 'XJM1P';`
`window['_fs_namespace'] = 'FS';`
`    if (e in m) {if(m.console && m.console.log) { m.console.log('FullStory namespace conflict. Please set window["_fs_namespace"].');} return;}`
`    g=m[e]=function(a,b,s){g.q?g.q.push([a,b,s]):g._api(a,b,s);};g.q=[];`
`    o=n.createElement(t);o.async=1;o.crossOrigin='anonymous';o.src='https://'+_fs_script;`
`    y=n.getElementsByTagName(t)[0];y.parentNode.insertBefore(o,y);`
`    g.identify=function(i,v,s){g(l,{uid:i},s);if(v)g(l,v,s)};g.setUserVars=function(v,s){g(l,v,s)};g.event=function(i,v,s){g('event',{n:i,p:v},s)};`
`    g.anonymize=function(){g.identify(!!0)};`
`    g.shutdown=function(){g("rec",!1)};g.restart=function(){g("rec",!0)};`
`    g.log = function(a,b){g("log",[a,b])};`
`    g.consent=function(a){g("consent",!arguments.length||a)};`
`    g.identifyAccount=function(i,v){o='account';v=v||{};v.acctId=i;g(o,v)};`
`    g.clearUserCookie=function(){};`
`    g.setVars=function(n, p){g('setVars',[n,p]);};`
`    g._w={};y='XMLHttpRequest';g._w[y]=m[y];y='fetch';g._w[y]=m[y];`
`    if(m[y])m[y]=function(){return g._w[y].apply(this,arguments)};`
`    g._v="1.3.0";`

app can’t be accessed in that way but there are a few options to help you minimize the number of FS hits.

You can have set app env script that is programmatically run when you decide, in that put your JS into a function action and then run it at your will. This will allow you to turn on and off FS from FM!

The issue with the way you are doing it is that the DOM insertions will only run once, when the app loads.

Ah, that makes sense. Thanks, Charles.