This article describe a solution for combining the following SiteCatalyst visit details plugins into a single JavaScript Code extension:
s.getVisitNum (https://marketing.adobe.com/resources/help/en_US/sc/implement/getVisitNum.html)
s.getNewRepeat (https://marketing.adobe.com/resources/help/en_US/sc/implement/getNewRepeat.html)
s.getVisitStart (https://marketing.adobe.com/resources/help/en_US/sc/implement/getVisitStart.html)
s.getDaysSinceLastVisit (https://marketing.adobe.com/resources/help/en_US/sc/implement/getDaysSinceLastVisit.html)
This article covers the following topics:
Table of Contents Placeholder
How it Works
The cpde sample in this article and the attached sitecatalyst-visit-details-code.txt file contains the JavaScript required to create a custom plugin. The plugin creates five (5) variables in the Tealium Data Layer that can then be mapped to a SiteCatalyst tag.
Creating and Deploying the Extension
Use the following steps to create and deploy the custom SiteCatalyst Visit Details extension:
Add a JavaScript code extension.
In the Title field, enter SiteCatalyst Visit Details Extension.
In the Scope field, keep the default setting, All Tags to ensure that new variables are available to all of your tags.
You can optionally set scope to the SiteCatalyst tag to reserve the functionality for SiteCatalyst.
In the Execution field, keep the After Load Rules (default) setting.
In the Configuration field, paste the code from your clipboard into the form box.
Click the Data Layer tab.
Define the following variables:
_visit_page_num
_visit_return
_visit_start
_visit_number
_visit_type
Map the new variables to the corresponding Adobe variables.
Click Save/Publish.
Sample SiteCatalyst Visit Details JavaScript
The following sample and attached sitecatalyst-visit-details-code.txt text file contains the JavaScript required to create this custom plugin.
// change the following as appropriate
var visit_timer = 30; //days since last visit
// end changes
(function (a, c, d, e, f, g, h, i, k, l, m, n, o, p, q, r, s, t,v) {
a = a ? parseInt(a) : 30;
n = v = 1;
r = function (w, x, y, z) {
// read cookie
x = w + "=";
y = document.cookie.split(';');
for (var i = 0; i < y.length; i++) {
z = y[i];
while (z.charAt(0) == ' ')
z = z.substring(1, z.length);
if (z.indexOf(x) == 0)
return z.substring(x.length, z.length);
}
return "";
};
q = function (x, y, z) {
// set cookie
if (typeof z == "number") z = new Date(z);
document.cookie = x + "=" + y + ";path=/;domain=" + utag.cfg.domain + ";expires=" + (z?z.toGMTString():"");
//b["cp."+x] = y; // add cookie to udo
};
d = new Date();
e = d.getTime();
f = 'utag_vnum';
g = 'utag_invisit';
o = 'utag_vs';
p = 'utag_dslv';
// get visit num and new/repeat
d.setTime(e + a*24*60*60*1000);
h = r(f);
if (h) {
i = h.substring(h.indexOf('&vn=') + 4, h.length);
k = h.substring(0, h.indexOf('&vn='));
}
if (r(g)) {
if (i) {
// return same visit num if already in visit
q(g, 'true', d.setTime(e + 30*60*1000));
m = i;
l = (e-(parseInt(k)-(a*24*60*60*1000)) < 30*60*1000) ? "New" : "Repeat";
} else {
// in case the cookie has been altered
m = l = "unknown";
}
} else {
if (i) {
// increment visit num
i++;
q(f, k+'&vn='+i, d.setTime(k));
q(g, 'true', d.setTime(e + 30*60*1000));
m = i;
l = "Repeat";
} else {
// set initial visit
q(f, e + a*24*60*60*1000 +'&vn=1', d);
q(g, 'true', d.setTime(e + 30*60*1000));
m = 1;
l = "New";
}
}
// visit start and page number
if (!(r(o))) { v = 1; }
if (r(o)) { n = 0; v=r(o); v++; }
if (!q(o, v, new Date().setTime(new Date().getTime() + 1800000))) q(o, v, 0);
if (!r(o)) n = v = 0;
// days since last visit code
s = new Date();
t = new Date();
c = s.getTime();
d = 24 * 60 * 60 * 1000;
s.setTime(c + 3 * 365 * d);
t.setTime(c + 30 * 60 * 1000);
f = c - r(p);
if (r(p).length == 0) {
q(p, c, s);
q(p + '_s', 'First Visit', t);
} else {
q(p, c, s);
if (d > 30 * 60 * 1000) {
if (f > 30 * d) {
q(p + '_s', 'More than 30 days', t);
} else if (f < 30 * d + 1 && f > 7 * d) {
q(p + '_s', 'More than 7 days', t);
} else if (f < 7 * d + 1 && f > d) {
q(p + '_s', 'Less than 7 days', t);
} else if (f < d + 1) {
q(p + '_s', 'Less than 1 day', t);
} else {
q(p, c, -1);
h = '';
}
} else {
q(p + '_s', r(p + '_s'), t);
}
}
e = r(p + '_s');
if (e.length == 0)
h = 'Cookies Not Supported';
else if ( e != 'First Visit'
&& e != 'More than 30 days'
&& e != 'More than 7 days'
&& e != 'Less than 7 days'
&& e != 'Less than 1 day'
)
h = '';
else
h = e;
b['_visit_page_num'] = v;
b['_visit_return'] = h;
b['_visit_start'] = n;
b['_visit_number'] = m;
b['_visit_type'] = l;
})(visit_timer);
... View more