Skip to content

Instantly share code, notes, and snippets.

@sdilshod
Created November 14, 2015 05:44
Show Gist options
  • Save sdilshod/25e4d6eccf26deb752cf to your computer and use it in GitHub Desktop.
Save sdilshod/25e4d6eccf26deb752cf to your computer and use it in GitHub Desktop.
<script type="text/javascript">
(function() {
window._pa = window._pa || {};
pa.src = ('https:' == document.location.protocol ? 'https:' : 'http:') + "//tag.marinsm.com/serve/53d212865be884e6aa00002b.js";
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(pa, s);
})();
dataLayer = [];
window.virtualPageCollection = {};
</script>
<% if params[:action] == 'index' # Landing only js (google) %>
<!-- Google Tag Manager -->
<noscript>
<iframe src="//www.googletagmanager.com/ns.html?id=GTM-XXXXXX" height="0" width="0" style="display:none;visibility:hidden">
</iframe>
</noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');
</script>
<!-- End Google Tag Manager -->
<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-XXXXXXXX-XX', 'auto');
ga('send', 'pageview');
</script>
<% end %>
class @LightboxTracker
config:
containers:
lightboxSelector: '#lightbox'
elements:
lightboxImageSelector: '.lb-image'
constructor: ->
@initializeVirtualPageCollection()
@binding()
binding: =>
$(@config.elements.lightboxImageSelector, @config.containers.lightboxSelector).on 'load', (event) =>
if $(@config.containers.lightboxSelector).css('display') != 'none'
imageSrc = $(event.currentTarget).prop('src')
virtualPageId = @findItem imageSrc
dataLayer.push
'event': 'lightboxVirtualPage',
'lightboxVirtualPageId': virtualPageId,
'lightboxVirtualPageTitle': imageSrc
initializeVirtualPageCollection: =>
window.virtualPageCollection['designed-by-coaches-for-coaches'] = []
$("a[data-lightbox=image-2]").each ->
window.virtualPageCollection['designed-by-coaches-for-coaches'].push($(@).prop('href'));
window.virtualPageCollection['app-features'] = []
$("a[data-lightbox=image-7]").each ->
window.virtualPageCollection['app-features'].push($(@).prop('href'));
window.virtualPageCollection['become-a-pro'] = []
$("a[data-lightbox=image-9]").each ->
window.virtualPageCollection['become-a-pro'].push($(@).prop('href'));
window.virtualPageCollection['sneak-peek'] = []
$("a[data-lightbox=image-8]").each ->
window.virtualPageCollection['sneak-peek'].push($(@).prop('href'));
findItem: (imageLink) =>
findedValue = ''
$.each window.virtualPageCollection, (key, value) ->
if $.inArray(imageLink, value) != -1
findedValue = key
return false
return findedValue
$(document).ready ->
new LightboxTracker()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment