SPM JS: Adding a script on a page to test

In some cases, you may be trying to run the Sailthru SPM JS on the site, but are running into errors. A common error is the "Sailthru is not defined" error. A common reason is due to RequireJS running on the site, but this JS file often is nested within other files and code, and makes it hard verify. 

A way to test this is pushing the script to load on the site in your own local browser instance, without actually adding the script to the production or staging site, through the use of a Chrome Extension and dev tool snippets.

  1. Add the Chrome Extension: Custom JavaScript for Websites (CJS)
  2. On the page you'd like to load the JS on, open the chrome extension and paste in the code snippet, making sure to swap the Customer ID placeholder for the one in your account
    require(["Sailthru"], function (Sailthru) {
    console.log("Optional log to show in Console that the SPM JS loaded onsite!");
    { customerId: '<customerID here>'}
  3. Click "your own external scripts" which will open up a box to load a script, paste in the source URL for the SPM JS. 
  4. Click Save. The page will reload, and will have run the script on the page.
  5. To verify it's working, open Chrome Dev Tools and search the Network tab for "spm".
  6. You can also load the Simple calls by creating a Snippet within Dev tools: Sources > Snippets > New Snippet > Paste the above code > hit Run.
  7. To verify it's working, return to the Network tab and search for "simple" to see the simple calls.