Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

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>  
share|improve this answer
    
from what I can read here: developers.google.com/analytics/devguides/collection/… it requires I use the Analytics.js version of google Analytics, right? –  abernier Feb 2 at 17:35
    
Polluting the code with garbage is so wrong that I think I'm reading your answer wrong. Are you actually suggesting to put google analytics code on a jsfiddle code? –  PatomaS Feb 5 at 1:09
    
@PatomaS, do you have a better option? –  abernier Feb 5 at 1:18
add comment

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.

  1. 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.

  2. 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.

share|improve this answer
    
Hey @PatomaS, I guess you are not answering the initial question, but give me a personal advice about my website? :) –  abernier Feb 5 at 1:16
    
well, yes and no, the thing is, if you have a good article/post, that is going to draw traffic to the jsfiddle code, but, this is the important part, I'm assuming that since you say that you use jsfiddle a lot, you will have an account, and so, people can see your username there and follow that information to your site. You can even put your site in a comment on the code, much better that polluting it with the other code. Also, how many times have you seen pages/codes from jsfiddle and similar places coming up as result of searches? –  PatomaS Feb 5 at 1:24
    
i'll update my answer since I have more space there. –  PatomaS Feb 5 at 1:25
    
I understand now :) I think that's a good and wise advice to do so, and a kind of workaround. But, you know, sometimes we're just lazy and even if I follow your advice for some of my jsfiddles, I'm not sure doing it for all of them... But thx for that answer, that's smart ;) –  abernier Feb 5 at 1:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.