Expand my Community achievements bar.

Get Time Parting Plugin Replication in DTM

Avatar

Level 1

Hi 

I'm trying to recreate the time parting plugin in DTM using data elements

The idea is to use the JS DOM date() function to populate a ever/prop and then to use the rule classification to split the string into the components ( saving me 3 variables)

i'm not a java script expert so but I've managed to get window.Date() to return back the value I want,

When I load window.Date as a jsobject in Data Elements it returns function Date() { [native code] }

Any help on this or Is there a better way to achieve this?

Thanks

Bhavin

2 Replies

Avatar

Level 2

You can use something like this as a custom script for your data element.

 

return (function () { "use strict"; var now = new Date(); var year = "" + now.getFullYear(); var month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; } var day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; } var hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; } return year + "-" + month + "-" + day + " " + hour; })();

Avatar

Level 2
var dt = new Date(); var day, hour, minutes, daytype; if (dt.getDay() == "0") { day = "Sunday"; daytype = "Weekend"; } else if { (dt.getDay() == "1") { day = "Monday"; daytype = "Weekday"; } else if { (dt.getDay() == "2") { day = "Tuesday"; daytype = "Weekday"; } else if { (dt.getDay() == "3") { day = "Wednesday"; daytype = "Weekday"; } else if { (dt.getDay() == "4") { day = "Thursday"; daytype = "Weekday"; } else if { (dt.getDay() == "5") { day = "Friday"; daytype = "Weekday"; } else if { (dt.getDay() == "6") { day = "Saturday"; daytype = "Weekend"; } var time = daytype + ":" + day + ":" + dt.getHours() + ":" + dt.getMinutes(); return(time);

Once you have the output of this data element (call it whatever, I called mine "Day and Time") you can setup a classification rule builder entry to break it up into Weekday/Weekend, Day of the Week, and Hour of the Day.  I didn't bother breaking up hour of the day by every 30 minute interval, but whatever, you could if you like.  I also didn't put in AM/PM, because I hated that for the longest time, makes it really hard to sort nicely.