Shopify点击计数器

时间:2016-09-29 17:12:44

标签: javascript ajax shopify click-counting

我正在尝试在shopify页面上创建一个简单的点击计数器,以便所有客户/客户能够看到。

  var a = []; // array of indexes
  var num_clicks = []; // stored number of clicks for each collection

  // Get titles of each collection to use as index
  a[0] = {{linklists[page.handle].links[0].title| json}};
  a[1] = {{linklists[page.handle].links[1].title| json}};
  a[2] = {{linklists[page.handle].links[2].title| json}};
  a[3] = {{linklists[page.handle].links[3].title| json}};
  a[4] = {{linklists[page.handle].links[4].title| json}};
  a[5] = {{linklists[page.handle].links[5].title| json}};
  a[6] = {{linklists[page.handle].links[6].title| json}};
  a[7] = {{linklists[page.handle].links[7].title| json}};
  a[8] = {{linklists[page.handle].links[8].title| json}};

  // Set all number of clicks to 0
  for(var i=0;i<9;i++){
    num_clicks[a[i]] = 0;
  }

  // counter
  function fn(clicked){
    var target; // some target number 
    var x; // div id where I'm putting the counter
    if(num_clicks[clicked] < min_click-1){
      num_clicks[clicked] += 1;
      document.getElementById(x).innerHTML = num_clicks[clicked]+" / " + target;
    } else{
      num_clicks[clicked] += 1;
      document.getElementById(x).innerHTML = num_clicks[clicked] +" / " + target;
      document.getElementById(clicked).href = "SOME LINK";
      return true;
    }
  }

此代码在一台计算机上工作正常,但我需要它以“全局”显示相同的数字,并且听说它必须在服务器端编写。但我无法弄清楚如何将计数器发送到服务器并检索它。如果你能帮我解决这个问题,我们将非常感激。

谢谢大家的帮助!

0 个答案:

没有答案