Forum Discussion

MColantonio's avatar
MColantonio
Community Member
15 days ago

Storyline 360 JavaScript does not run in Publish mode...

I have JavaScript on each of my buttons (which also has an additional jump to slid action on it) and the JavaScript runs in preview mode but will not run in Published mode. Any help or ideas would be greatly appreciated.

Here is the JavaScript I'm using:

const url = 'https://api.getdx.com/events.track';
const apiKey = 'XXXXXXXXXXXXXXXXXXXXX';
const data = { 
  name: "BANGING MY HEAD!", // customize your event names
  email: 'Yourname@email.com', // replace this with dynamic data 
  timestamp: Math.floor(Date.now() / 1000).toString(),
  metadata: { 
    page: window.location.href, // Optionally track the page URL 
    referrer: document.referrer // Optionally track referrer
  }
}; 

fetch(url, { 
  method: 'POST', 
  headers: { 
    'Content-Type': 'application/json', 
    'Authorization': `Bearer ${apiKey}`
  }, 
  body: JSON.stringify(data) 
}); 

 

 

Thank you,

Mark

  • Nedim's avatar
    Nedim
    Community Member

    The JavaScript syntax itself looks correct. Unfortunately, I don't have the full context of the issue you're facing. I suggest checking for potential errors in the browser's console when the course is published to Web, SCORM, or Review 360. You could also try using the updated version of your code (attached), which includes error handling and comments for debugging purposes. 

    I suspect the code you provided could potentially run into CORS issues. Have you tried publishing the course to the Web and running it on a local server?

    • MColantonio's avatar
      MColantonio
      Community Member

      Hi Nedim ,

      Thank you for your reply. I am publishing this to the Web. What's weird is that it works perfectly in preview mode and then once published for the web, it stops working. I don't even see it running in the browser console. It used to work, and just stopped. 

      • Nedim's avatar
        Nedim
        Community Member

        When you publish to Web, your slide is likely running from a local path (e.g., file:///C:/path/to/story.html) instead of a local server. I’m assuming it’s running from a local path. Try opening your project folder in an editor like Visual Studio Code, navigate to story.html, and start it using the Live Server extension. This will simulate a server environment with a local server address, such as 127.0.0.1:5500/story.html. Does it work in Review 360? Alternatively, you can publish your project to SCORM and upload it to your LMS or SCORM Cloud. Afterward, confirm if your code is working.