Like/Share button

Like button will allow visitors on your site to mark favorite materials and share them with friends on Odnoklassniki.

It will help you understand what your audience is more like it, and at the same time attract new visitors to your site.

Like button builder

Link

Appearance

Size
Form
Background color
#
Text color
#

Additional data(?)

Title
Description
Image URL

Result

Code to insert

How our grabber work

When sharing a resource on Odnoklassniki, problems may occur with the media content processing.

Restrictions on sharing images:

  • min size:
    • web: 128x128
    • mobile: 50x50
  • min aspect ratio: 0.5

For untrusted domains grabber does not handle images and video. You should use one of the page layouts protocols:

  • Open Graph This method allows you to set specific tags like og:title, og:description, og:image and og:video in a <head></head> html-tag to help grabber choosing which content to use on this page.
  • OExchange

Additional features

  • You can use “share” without setting a button, for this you need to open a link in following form:
https://connect.ok.ru/offer
   ?url=URL_TO_SHARE
   &title=TITLE
   &imageUrl=IMAGE_URL

Only the url parameter is required, the other parameters are optional.

  • The ability to know the number of “shares” to your page without setting a button:
https://connect.ok.ru/dk
   ?st.cmd=extLike
   &tp=json
   &ref=URL_TO_SHARE

Grabber requests are sent from:

  • 217.20.144.0/20
  • 5.61.16.0/21

Embedding multiple widgets

To embed multiple widgets on a single page you can use the code:

!function (d, id, did, st) {
  var js = d.createElement("script");
  js.src = "https://connect.ok.ru/connect.js";
  js.onload = js.onreadystatechange = function () {
  if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
    if (!this.executed) {
      this.executed = true;
      setTimeout(onOkConnectReady, 0);
    }
  }}
  d.documentElement.appendChild(js);
}(document);
function onOkConnectReady() {
  OK.CONNECT.insertGroupWidget("mineGroupWidgetDivId","50582132228315","{width:250,height:335}");
  OK.CONNECT.insertShareWidget("mineShareWidgetDivId","https://apiok.ru","{width:125,height:25,st:'oval',sz:12,ck:1}");
}

Like event tracking

On like event widget sends a postMessage with following data

ok_shared$__okShare1

You can track event on page with widget by the following javascript code:

function listenForShare() {
    if (window.addEventListener) {
        window.addEventListener('message', onShare, false);
    } else {
        window.attachEvent('onmessage', onShare);
    }
}

function onShare(e) {
    var args = e.data.split("$");
    if (args[0] == "ok_shared") {
        alert(args[1]);
    }
}

listenForShare();