Analytics
4.5K members online now
4.5K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

events tracking- javascript

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hi everyone,

I have a single-page-website and I'm trying to get meaningful analytic stats.

I searched the web and found some javascript code lines that I want to combine:



<!-- Google Analytics code -->

<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','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-81123633-1', 'auto');
  ga('send', 'pageview');
setTimeout("ga('send', 'event', { eventCategory: '10 seconds on page', eventAction: 'Read' })", 10000);
</script>

and that:

<script>
var runned = false;
$( window ).scroll( function() {
  if ( $( document ).scrollTop() >= 150 && runned == false ) {
    ga('send', 'event', { eventCategory: 'Scrolled 150px', eventAction: 'Scroll' });
  runned = true;
  }
});

</script>

now if I just paste them one after the other- the first one works and the second doesn't affect anything. how can I define both of them as different events?

 

Thank you very much!

Hofit

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author hofit t
August 2016

Re: events tracking- javascript

Top Contributor
# 2
Top Contributor

Hi Hofit,

 

You need to include the jquery library on your page in order to use the scroll event.

 

You can download the jquery library from https://jquery.com/download/ or you can use the google hosted library:

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 

Hope this helps.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author hofit t
August 2016

Re: events tracking- javascript

Top Contributor
# 2
Top Contributor

Hi Hofit,

 

You need to include the jquery library on your page in order to use the scroll event.

 

You can download the jquery library from https://jquery.com/download/ or you can use the google hosted library:

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> 

Hope this helps.


Arnold Majlath, Google Analytics Top Contributor
Was my response helpful? If yes, please accept it as solution.
Circle Me On Google+ | Visit me @ Redfly Digital

Re: events tracking- javascript

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭
It helped indeed! Smiley Happy Thank you very much!