tracker.ejs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <% var title = "" %>
  2. <% if(page.canonical_path == 'index.html') { %>
  3. <% title = "Landing Page view" %>
  4. <% } else { %>
  5. <% if(page != undefined) { %>
  6. <% if(page.content_type != undefined) { %>
  7. <% title = page.content_type.charAt(0).toUpperCase() + page.content_type.slice(1); %>
  8. <% } else if (page.title != undefined) { %>
  9. <% title = page.title.charAt(0).toUpperCase() + page.title.slice(1); %>
  10. <% } else { %>
  11. <% title = "Page"; %>
  12. <% } %>
  13. <% } else { %>
  14. <% title = "Page"; %>
  15. <% } %>
  16. <% } %>
  17. <% if(page.content == undefined) { %>
  18. <script>
  19. if (location.hostname !== "localhost" && location.hostname !== "127.0.0.1"){
  20. mixpanel.track("<%- title %>");
  21. } else {
  22. console.log('No tracking in ' + location.hostname);
  23. console.log(`Tracking: \'<%- title %>\'`)
  24. }
  25. </script>
  26. <% } else { %>
  27. <script>
  28. var payload = { content : "<%- page.title %>" };
  29. if (location.hostname !== "localhost" && location.hostname !== "127.0.0.1"){
  30. mixpanel.track("<%- title %> view", payload);
  31. } else {
  32. console.log('No tracking in ' + location.hostname);
  33. console.log(`Tracking: \'<%- title %> view\'`, payload)
  34. }
  35. </script>
  36. <% } %>