Skip to main content
The library ships as https://app.surferseo.com/static/surfer_guidelines_1_x_x.js, which tracks the 1.x line (Versioning), and puts three functions on window.surferGuidelines. The quickstart shows the loader and one working call. Embedding Surfer needs the arrangement and the browser requirements under Availability. The panel the library mounts shows one Content Editor, the document Surfer builds around your target keywords, holding the guidelines and the Content Score; the panel scores the HTML you send against those guidelines (The guidelines panel). The library exchanges postMessage commands with the panel’s iframe and is the supported client, so the message format is not documented.

window.surferGuidelines.init

init mounts the panel inside an element you own and returns nothing; use it when the four callbacks it accepts are enough. The declaration, as the library ships it:
Parameters: What init does, in order:
  1. Creates the iframe, adds the surfer-guidelines class to it, and appends it to target, unsized; see $iframe under The handle.
  2. Sets the permalink from options.permalink, the page URL, and sharingToken, as Permalinks describes.
  3. Sends the HTML from any window.surferGuidelines.setHtml call made before init ran.
  4. Points window.surferGuidelines.setHtml at the mounted panel.
onNavigation, onDraftLoaded, and onStructuralGuidelinesChanged are not among init’s options, and init returns no handle. initWithOptions below covers both.

window.surferGuidelines.setHtml

setHtml sends the article HTML to the panel. Call it after every change to the text. The declaration:
html is the article’s HTML only; the panel does not extract an article from a whole page. The panel ignores HTML identical to what it already holds. Calls made before init are kept, last one wins, and sent once init runs. After init this is the same function as the handle’s setHtml.

window.surferGuidelines.initWithOptions

initWithOptions creates the iframe without attaching it and returns a handle with the iframe element and every method. Use it for the callbacks init does not take, or to place the iframe yourself. The declaration below shows the library as it behaves at runtime. The shipped declaration file types getMatchedTerms as synchronous, lists a view the panel no longer honors, and lists two configureView flags the panel ignores:

Options

Every option is optional; anonymous and partner shape the iframe URL, and each callback receives what the panel sends today. Fields of opts: onContentScoreDetailsChanged receives a ContentScoreDetails object with this shape:
  • competitors_avg is the rounded average Content Score of the qualifying competitors.
  • competitors_max is the highest Content Score among them, not rounded.
  • A competitor qualifies when it is selected in the Content Editor, its analysis has completed, it is not excluded, and its score is above zero.
  • Both fields are absent when no competitor qualifies.
  • Each group in details is one part of the score.
  • value is the points earned in that group and maxValue the points available.
Each item of onTermsToUseChanged is a term with this shape, and onFocusTermChanged receives one term of the same shape:
  • item is the term text.
  • heading says whether the guidelines want the term in a heading.
  • nlpEntity says whether the term comes from Surfer’s entity analysis.
  • usage.current is the term’s count in the HTML.
  • usage.optimal is the recommended count range.
  • usage.suboptimal is the count range the panel flags as a warning.
Each item of onStructuralGuidelinesChanged is a structure guideline with this shape:
  • value is the count measured in the HTML.
  • target is what the competitors use.
  • ranges are the bands the panel grades the value against.

The handle

The handle holds the iframe and six methods bound to it. All but getMatchedTerms can be called before the iframe is attached or the panel has loaded. The library sends the call once the panel is ready. getMatchedTerms starts its timeout on the call, so it needs a loaded panel. Members of the returned object: Each word segment in a matches entry gives the word’s index in the held HTML. At runtime it also carries segment, isWordLike, and breakType, while the declaration file lists only index and originalSegment.

View flags

Flags configureView accepts, each false unless set:

Example

Take configureView, requestView, and getMatchedTerms from the handle the quickstart creates with initWithOptions. Run after the quickstart’s setHtml call, this code hides the batch option in the dashboard, shows the Content Score on its own, and finds two terms in the HTML the panel holds:
configureView and requestView are held until the panel is ready. getMatchedTerms searches the HTML the library has delivered, which happens once a Content Editor has loaded, so call it after onDraftLoaded has received a permalink; when the panel does not answer within 1000 ms the promise rejects with Timeout.

Behavior to plan for

Four behaviors of the library decide how a host is built.
  • There is no dispose method. The library keeps a message listener on window for the life of the page. Mount once per page, reuse the handle, and change Content Editors with setPermalink.
  • A score of zero is not emitted, and neither is its breakdown. Treat “no callback yet” as no score.
  • Callbacks are asynchronous. The panel re-scores after each setHtml whose HTML differs from the last. The score callbacks fire when that finishes, never on your call stack. The panel holds no timer of its own, so the delay is the scoring.
  • The panel signs in with the writer’s Surfer session, through the browser’s cookies for Surfer. Access and sharing covers the modes and the cookie requirements.

Versioning

surfer_guidelines_1_x_x.js is the current 1.x build; a pinned file freezes the library, not the panel.
  • Pinned builds are named surfer_guidelines_1_<minor>_<patch>.js; the newest is surfer_guidelines_1_3_1.js, and today 1_x_x serves the same file.
  • The panel is part of the Surfer app and updates on its own schedule whichever file you load. A pinned build keeps the library behavior of that release, including which callbacks and handle members it has.
  • The library accepts messages from any 1.x panel and the panel from any 1.x library.