# anki integration

**URL:** <https://forum.beeminder.com/t/anki-integration/10376>\
**Category:** Tech\
**Created:** [May 27, 2022, 3:52am UTC](https://forum.beeminder.com/t/anki-integration/10376 "2022-05-27T03:52:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![skorytnicki](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/skorytnicki/32/4204_2.png) [@skorytnicki](https://forum.beeminder.com/u/skorytnicki)\
**Post date:** [December 10, 2022, 8:59pm UTC](https://forum.beeminder.com/t/anki-integration/10376/4 "2022-12-10T20:59:06Z")

</div>

Anki was driving me nuts - it’s hard to replace Anki and their platform is limited for a reason. To keep it free, they had to make some constraints. Nonetheless I am not able to have plugins for Anki mobile, I can’t spin up my custom sync server and I can’t have any API endpoint to retrieve the data. I can write a bot to login to AnkiWeb and read data, but it isn’t nice solution.

I came up with a bit different one to make sure to sync data with beeminder. It should work on every platform and is quite elastic. You can execute JS in a card template. In your card template, you can add a snippet of code in either “back” or “front”:

```auto
<script>
(() => {
  if (typeof window._skcount === "undefined") {
    window._skcount = 0;
  }
  window._skcount += 1;

  const $debug = document.querySelector("#skcount");
  $debug.innerHTML = window._skcount;

  const SYNC_EVERY_X_CARDS = 10;
  const USER = "YOUR_NAME";
  const AUTH_TOKEN = "YOUR_TOKEN";
  const GOAL = "YOUR_GOAL";

  if (window._skcount % SYNC_EVERY_X_CARDS === 0) {
    fetch(`https://www.beeminder.com/api/v1/users/${USER}/goals/${GOAL}/datapoints.json?auth_token=${AUTH_TOKEN}`, {
      headers: {
        "Content-Type": "application/json",
      },
      method: "POST",
      body: JSON.stringify({ value: SYNC_EVERY_X_CARDS, comment: new Date().toString() }),
    })
      .then(() => {
        $debug.innerHTML = "Saved to Beeminder!";
      })
      .catch((error) => ($debug.innerHTML = error.message));
  }
})();
</script>

```

Please fill the template with your goal data and also place in your card this snippet: `<div id="skcount"></div>` to see which card is it and see syncing status.

This script will add a beeminder data every X cards you review. It works for me on Anki MacOS, AnkiMobile (iOS) and AnkiWeb. Obviously it has a downside if you spread your efforts thin across different decks (20 decks, 5 cards to review in each).  
Similarly, we can use JavaScript tricks to beemind beenary goals (did I review at least 1 card today?) or perhaps create “time spent on Anki” goal.

---

_[View the full topic](https://forum.beeminder.com/t/anki-integration/10376)._
