Back to Code List
javascript

Time Parting Plugin

This is the standard SiteCatalyst time parting plugin that has been formatted to work with any analytics that you desire. All that is needed is to paste on a page. It will output the time, day, and day type that the regular plugin outputs. You can use these for any analytics case that you may need.

   tooltips.txt

Tooltips:

Timezone:
    The desired timezone for your reporting that you'd like the values to be in. Automatically accounts for DST.
Current Time:
    Returns the user visit time according to the given timezone. Format is "4:00PM" and is given to the nearest 15 minute interval.
Current Day:
    Gives the current day for the user's visit according to the given timezone. Ex. Thursday
Day Type:
    Gives the type of day the user has visited for the given timezone. Ex. Weekday or Weekend.
Additional Extension Information:
    Use this extension to get a user's visit time data based on a given timezone. Provides time, day, and day type that may be mapped to a data source.    

   code_to_paste.js

// change the following variables as needed
    var timezone = '-6';
    
// end changes

//this is the output variable. After the function
//runs, assign values inside here as needed
var b = {};

(function (a, q, c, d, e, f, g, h, i, k, l, m, n, p) {
    try {
        c = new Date();
        q = c.getFullYear();
        d = new Date('1/1/2000');
        e = 15;
        f = 8;
        if (d.getDay() == 6 && d.getMonth() == 0 && typeof a != "undefined" && a != "" && a != null) {
            a = parseInt(a);
            if (q == 2009) {
                e = 8;
                f = 1;
            }
            g = e - new Date('3/1/' + q).getDay();
            h = f - new Date('11/1/' + q).getDay();
            if (c > new Date('3/' + g + '/' + q) && c < new Date('11/' + h + '/' + q)) {
                a = a + 1;
            }
            i = new Date((c.getTime() + (c.getTimezoneOffset() * 60000)) + (3600000 * a));
            k = i.getHours();
            l = i.getMinutes();
            m = i.getDay();
            n = 'AM';
            p = '00';
            if (l > 15 && l < 30) {
                p = '15';
            } else if (l > 30 && l < 45) {
                p = '30';
            } else if (l > 45 && l < 60) {
                p = '45';
            }
            if (k >= 12) {
                n = 'PM';
                k = k - 12;
            } else if (k == 0) {
                k = 12;
            }
            b["_timeparting_time"] = k + ':' + p + n;
            b["_timeparting_day"] = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][m];
            b["_timeparting_type"] = (m == 6 || m == 0) ? "Weekend" : "Weekday";
        }
    } catch (err) {}
})(timezone);