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:
What
init does, in order:
- Creates the iframe, adds the
surfer-guidelinesclass to it, and appends it totarget, unsized; see$iframeunder The handle. - Sets the permalink from
options.permalink, the page URL, andsharingToken, as Permalinks describes. - Sends the HTML from any
window.surferGuidelines.setHtmlcall made beforeinitran. - Points
window.surferGuidelines.setHtmlat 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_avgis the rounded average Content Score of the qualifying competitors.competitors_maxis 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
detailsis one part of the score. valueis the points earned in that group andmaxValuethe points available.
onTermsToUseChanged is a term with this shape, and onFocusTermChanged receives one term of the same shape:
itemis the term text.headingsays whether the guidelines want the term in a heading.nlpEntitysays whether the term comes from Surfer’s entity analysis.usage.currentis the term’s count in the HTML.usage.optimalis the recommended count range.usage.suboptimalis the count range the panel flags as a warning.
onStructuralGuidelinesChanged is a structure guideline with this shape:
valueis the count measured in the HTML.targetis what the competitors use.rangesare the bands the panel grades the value against.
The handle
The handle holds the iframe and six methods bound to it. All butgetMatchedTerms 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
FlagsconfigureView accepts, each false unless set:
Example
TakeconfigureView, 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
windowfor the life of the page. Mount once per page, reuse the handle, and change Content Editors withsetPermalink. - 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
setHtmlwhose 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 issurfer_guidelines_1_3_1.js, and today1_x_xserves 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.