Reputation: 111
I'm trying to make a simple click counter on my shopify page for all the clients/customers to be able to see.
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;
}
}
This code works fine and all on one computer but I need it to show the same number "globally" and heard it has to written in server-side. but I can't figure out how to send the counter to the server and retrieve it. if you could help me out with this, it'd be very appreciated.
Thank you all for the help!
Upvotes: 1
Views: 265