frontend.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Frontend events tracking.
  4. *
  5. * @since 6.0.0
  6. *
  7. * @package MonsterInsights
  8. * @author Chris Christoff
  9. */
  10. // Exit if accessed directly
  11. if ( ! defined( 'ABSPATH' ) ) {
  12. exit;
  13. }
  14. /**
  15. * Get frontend tracking options.
  16. *
  17. * This function is used to return an array of parameters
  18. * for the frontend_output() function to output. These are
  19. * generally dimensions and turned on GA features.
  20. *
  21. * @since 7.0.0
  22. * @access public
  23. *
  24. * @return array Array of the options to use.
  25. */
  26. function monsterinsights_tracking_script( ) {
  27. require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/class-tracking-abstract.php';
  28. $mode = is_preview() ? 'preview' : 'analytics';
  29. do_action( 'monsterinsights_tracking_before_' . $mode );
  30. do_action( 'monsterinsights_tracking_before', $mode );
  31. if ( $mode === 'preview' ) {
  32. require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/tracking/class-tracking-preview.php';
  33. $tracking = new MonsterInsights_Tracking_Preview();
  34. echo $tracking->frontend_output();
  35. } else {
  36. require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/tracking/class-tracking-analytics.php';
  37. $tracking = new MonsterInsights_Tracking_Analytics();
  38. echo $tracking->frontend_output();
  39. }
  40. do_action( 'monsterinsights_tracking_after_' . $mode );
  41. do_action( 'monsterinsights_tracking_after', $mode );
  42. }
  43. add_action( 'wp_head', 'monsterinsights_tracking_script', 6 );
  44. //add_action( 'login_head', 'monsterinsights_tracking_script', 6 );
  45. /**
  46. * Get frontend tracking options.
  47. *
  48. * This function is used to return an array of parameters
  49. * for the frontend_output() function to output. These are
  50. * generally dimensions and turned on GA features.
  51. *
  52. * @since 6.0.0
  53. * @access public
  54. *
  55. * @return array Array of the options to use.
  56. */
  57. function monsterinsights_events_tracking( ) {
  58. $events_mode = monsterinsights_get_option( 'events_mode', false );
  59. $track_user = monsterinsights_track_user();
  60. if ( $track_user && ( $events_mode === 'js' || $events_mode === 'php' ) ) {
  61. require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-analytics-events.php';
  62. new MonsterInsights_Analytics_Events();
  63. } else {
  64. // User is in the disabled group or events mode is off
  65. }
  66. }
  67. add_action( 'template_redirect', 'monsterinsights_events_tracking', 9 );
  68. /**
  69. * Add the UTM source parameters in the RSS feeds to track traffic.
  70. *
  71. * @since 6.0.0
  72. * @access public
  73. *
  74. * @param string $guid The link for the RSS feed.
  75. *
  76. * @return string The new link for the RSS feed.
  77. */
  78. function monsterinsights_rss_link_tagger( $guid ) {
  79. global $post;
  80. if ( monsterinsights_get_option( 'tag_links_in_rss', false ) ){
  81. if ( is_feed() ) {
  82. if ( monsterinsights_get_option( 'allow_anchor', false ) ) {
  83. $delimiter = '#';
  84. } else {
  85. $delimiter = '?';
  86. if ( strpos( $guid, $delimiter ) > 0 ) {
  87. $delimiter = '&amp;';
  88. }
  89. }
  90. return $guid . $delimiter . 'utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=' . urlencode( $post->post_name );
  91. }
  92. }
  93. return $guid;
  94. }
  95. add_filter( 'the_permalink_rss', 'monsterinsights_rss_link_tagger', 99 );