Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track whether the bottom of the page is reached #37

Open
trajano opened this issue Dec 31, 2016 · 2 comments
Open

Track whether the bottom of the page is reached #37

trajano opened this issue Dec 31, 2016 · 2 comments

Comments

@trajano
Copy link
Owner

trajano commented Dec 31, 2016

Track whether we reached the bottom of the page where the contact info is

This was referenced Jan 7, 2017
@trajano
Copy link
Owner Author

trajano commented Jan 11, 2017

<script>
  // JQuery-visible
!function(t){var i=t(window);t.fn.visible=function(t,e,o){if(!(this.length<1)){var r=this.length>1?this.eq(0):this,n=r.get(0),f=i.width(),h=i.height(),o=o?o:"both",l=e===!0?n.offsetWidth*n.offsetHeight:!0;if("function"==typeof n.getBoundingClientRect){var g=n.getBoundingClientRect(),u=g.top>=0&&g.top<h,s=g.bottom>0&&g.bottom<=h,c=g.left>=0&&g.left<f,a=g.right>0&&g.right<=f,v=t?u||s:u&&s,b=t?c||a:c&&a;if("both"===o)return l&&v&&b;if("vertical"===o)return l&&v;if("horizontal"===o)return l&&b}else{var d=i.scrollTop(),p=d+h,w=i.scrollLeft(),m=w+f,y=r.offset(),z=y.top,B=z+r.height(),C=y.left,R=C+r.width(),j=t===!0?B:z,q=t===!0?z:B,H=t===!0?R:C,L=t===!0?C:R;if("both"===o)return!!l&&p>=q&&j>=d&&m>=L&&H>=w;if("vertical"===o)return!!l&&p>=q&&j>=d;if("horizontal"===o)return!!l&&m>=L&&H>=w}}}}(jQuery);
var trackedElements = [ ".page-footer .container h5" ]
function fireWhenVisible() {
  trackedElements = trackedElements.forEach(function(e){
    if ($(e).visible()) {
  	dataLayer.push({'event': 'element_visible_' + e});
       	return true
    } else {
      return false
    }
  })
}
$(window).on('blur', fireWhenVisible)
$(window).on('scroll', fireWhenVisible)
</script>

@trajano
Copy link
Owner Author

trajano commented Jan 12, 2017

The code requires JQuery to be present which in our case isn't because the script is loaded in HEAD and so the timing may not be there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant