Tracker 2.x

Legacy documentation for Tracker 2.x.

This tag allows you to display Tracker stats for a given entry.

{exp:tracker:stats} content {/exp:tracker:stats} 

Parameters

The following parameters are available for use:

entry_id=

entry_id="{entry_id}" 

This parameter tells Tracker which entry to pull statistics for. The entry ID can be hardcoded, passed through an embed, or parsed from the URI using {segment_3}. This parameter or the url_title parameter is required.

url_title=

url_title="{url_title}" 

This parameter tells Tracker which entry to pull statistics for. The URL title can be hardcoded, passed through an embed, or parsed from the URI using {segment_3}. This parameter or the entry_id parameter is required.

channel=

channel="articles" 

This parameter is required when using the url_title parameter method, as URL titles are NOT unique across channels.

site=

site="clothing" 

This parameter is required when using MSM on your site (if Multiple Site Manager is installed).

Variables

The following variables are available for use:

tracker_alltime_views

{tracker_alltime_views} 

This variable will display all views recorded for the given entry for all time.

tracker_current_year_views

{tracker_current_year_views} 

This variable will display all views recorded for the given entry for the current year.

tracker_current_month_views

{tracker_current_month_views} 

This variable will display all views recorded for the given entry for the current month.

tracker_current_week_views

{tracker_current_week_views} 

This variable will display all views recorded for the given entry for the current week.

tracker_today_views

{tracker_today_views} 

This variable will display all views recorded for the given entry for today.

tracker_yesterday_views

{tracker_yesterday_views} 

This variable will display all views recorded for the given entry for yesterday.

tracker_last_X_days_views

{tracker_last_30_days_views} 

This variable will display all views recorded for the given entry for the specified period of time. It allows you to display a timeframe (from today, backward) from which to count tracked views for the given entries. It accepts values like: last_30_days, last_2_weeks, last_3_months, and last_1_year.

Examples

The following are a few different examples of how you can use this tag:

Display Stats for an Entry in a Single Entry Page

{exp:channel:entries
    channel="articles"
    require_entry="yes"
}
    <h2>{title}</h2>
    <p>{body}</p>
    {if no_results}
        <p>Sorry, no entry was found.</p>
    {/if}

    <h3>Statistics for this entry:</h3>
    <ul>
    {exp:tracker:stats
        entry_id="{entry_id}"
    }
        <li>All Time: {tracker_alltime_views}</li>
        <li>Current Year: {tracker_current_year_views}</li>
        <li>Current Month: {tracker_current_month_views}</li>
        <li>Current Week: {tracker_current_week_views}</li>
        <li>Today: {tracker_today_views}</li>
        <li>Yesterday: {tracker_yesterday_views}</li>
        <li>Last 30 Days: {tracker_last_30_days_views}</li>
    {/exp:tracker:stats}
    </ul>

{/exp:channel:entries}

Display Simple Stats for Each Entry in a List of Entries

{exp:channel:entries
    channel="articles"
    limit="20"
}
    <div class="entry">
        <h2><a href="{url_title_path='articles/entry'}">{title}</a></h2>
        <p>{body}</p>
        <p>
            Total views for this entry:
            {exp:tracker:stats
                entry_id="{entry_id}"
            }
                {tracker_alltime_views}
            {/exp:tracker:stats}
        </p>
        {if no_results}
            <p>Sorry, no entry was found.</p>
        {/if}
    </div>
{/exp:channel:entries}