: How to make visits count on Google Analytics if someone visits my own JSFiddle on my website? I'm a developer and I often write JSFiddles for example. I use Google Analytics on my personal
I'm a developer and I often write JSFiddles for example. I use Google Analytics on my personal website to monitor traffic. jsfiddle.net is not my own domain, but in a way, snippets I'm publishing on belongs to me.
How can I make traffic my own JSFiddles' generate counts for my own domain's one? In other words, when someone visits a JSFiddle I have written, I'd like it counts for one visits on Google Analytics.
More posts by @Chiappetta492
3 Comments
Sorted by latest first Latest Oldest Best
JSFiddle does not offer Google Analytics tracking as a feature, but it can be done.
Create a .js file with your Google Analytics tracking code and save this to a publicly accessible web hosting location.
Then add your .js file as an external resource to all of your JSFiddles. Sadly this does need to be done to each Fiddle, BUT it keeps your code out of the code, and if you ever need to make changes to your GA code it's one change for all Fiddles.
Since you are publishing examples, the best way to use them in your site is to have clear descriptions of what the code does, elaborate the idea that you are showing, the reason why you choose something instead of another option, some caveats, what you accomplish with that code, how can you call it, or integrate it, or whatever is related to the piece of code that you are publishing.
There are tons of code examples on Internet, but very little good explanations. Help to change that. If you do, that will help you, and your readers much more.
Lets consider some scenarios.
People get to your site, read the article/post and go to your jsfiddle/code. From the traffic perspective, you already have what you want, you already had a visitor. If your explanation and your code are good enough, that person will come back some other time. If your explanation is bad, most probably won't even go to see your code. I wouldn't. Adding extra code to your original code, will make it more complex, and require that you explain that some parts are not required, which implies more work from your part and the reader. There is almost never a good reason to do extra work.
People get to your jsfiddle/code, without going to your site. What is that code for? how did they get there? why there is an analytics code on the script? do I need that part for the code to work? if not, why did the programmer put it there?. Plus the above consideration, you had to add more explanations to the code to make clear which part is needed and which is not.
To the second scenario, I have to add, how many times have you made a search and there have been jsfiddle results on it? or pastebin, or sqlfiddle, or any other site similar?. In my experience, less than 1%, only when the search is extremely specific and there are like 4 results on the whole Internet (crawled). And they are never useful. So, is it worth polluting your code for, how many visits?.
Now, for any scenario, assume that you add a brief comment, adding your site, your email or the url of the article where the code is explained, that is much more useful because the visitor can keep it and have a reminder of your site/name/article and visit it from time to time. Even more, if your code is complex enough and can be improved, you may add in the comment something like there will be new versions referenced on the original article, which will, in turn, grant more visits.
There are more options, but this is getting too long already. The important part is that if you just try to get traffic/visitors/views without providing something useful for the user, that is an empty experience and doesn't benefit anybody.
It is simple. In your JSFiddle you put your code. I mean Google Analytics of your website. something like this .change the id to yours.
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function()
{
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
}
)(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-your id-1', 'http://abernier.name/');
ga('send', 'pageview');
</script>
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.