Custom Tags examples

Rory_A

Administrator
Staff member
#1
Howto : tag affiliate info in the stats

Let's say you runs www.BobsRentals.com and the site www.RentalSource.com links to you like this

http://www.BobsRentals.com/page1.html?id=RentalSource

You can use some code to pass that id into the Custom Tags report in StatCounter. This will help you keep track of affiliates linking to you. In your reports you will see something like this

upload_2017-9-8_19-15-36.png

This code must go before your StatCounter tracking code.

<script type="text/javascript">
var myRE = /\?id=\w*/g;
var _statcounter = _statcounter || [];
var x;
try {x = document.URL.match(myRE)[0].slice(4);
_statcounter.push({"tags": {"affiliate": x}});
} catch(e) {}
</script>

Note the bold ?id=

This needs to be changed to whatever parameter name you would like to track

Also note the bold slice(4)

This represents the first part that identifies the data you want (?id=), but is not part of that data. For example if your landing URL is like this

http://www.BobsRentals.com/page1.html?linkID=RentalSource

Then your code would look like this

<script type="text/javascript">
var myRE = /\?linkID=\w*/g;
var _statcounter = _statcounter || [];
var x;
try {x = document.URL.match(myRE)[0].slice(7);
_statcounter.push({"tags": {"affiliate": x}});
} catch(e) {}
</script>

In this case the text ?linkID= is 7 characters long and we need to trim that off.
 
Last edited:

Rory_A

Administrator
Staff member
#2
Howto : note specific pages in the stats (such as your Contact or Sales page)



(1) change the bold info below to match what pages you want to tag / note in the stats
(2) put the code on your website so it's just before the StatCounter tracking code

<script type="text/javascript">
var _statcounter;
var currentPage = window.location.pathname.split("/").pop();

// customize pageOfNote variable below with your info

var pagesOfNote = ["contact.html", "sales.html", "hours.html"];
var customTagNote = currentPage
var pageMatch = pagesOfNote.indexOf(currentPage)
if (pageMatch > -1) {
zpush();
}
function zpush () {
_statcounter = _statcounter || [];
_statcounter.push({"tags": {"note": customTagNote}});
}
</script>
 
Last edited:
Top