I really like this post that shows working profile scripts. I am just simply looking for an example like one of these that shows how to capture a user metric on a given page. Here are a few example I am looking to create a profile script for:
1. User to homepage.com/product that has spent more than 60 seconds on that page.
2. User to homepage.com/product scrolled 50% or more.
3. User to homepage.com/product was referred by Google but recorded a bounce.
Thank you for any help!
Views
Replies
Total Likes
Please refer below URLs for your use-case.
Hi @bkrane2 ,
1. Time Spent on Page > 60s
if (mbox.name === "target-global-mbox") {
var timeSpent = (Date.now() - window.performance.timing.navigationStart) / 1000;
if (timeSpent > 60) {
return "spent_60_seconds";
}
}
return "under_60_seconds";
2. Scrolled 50% or More
This must be set via custom JavaScript on the site and passed via mbox parameter:
// On site, before firing mbox:
window.addEventListener('scroll', function () {
var scrolled = window.scrollY + window.innerHeight;
var fullHeight = document.body.scrollHeight;
if ((scrolled / fullHeight) >= 0.5) {
adobe.target.trackEvent({mbox: "target-global-mbox", params: {"scrolledHalf": "true"}});
}
});
Then in Target profile script:
return user.get('scrolledHalf') === "true" ? "scrolled_50_plus" : "not_scrolled_50";
3. Came from Google + Bounce Detection
You'd need to set entryPage via JavaScript on the user's first pageview.
if (document.referrer.includes("google.com")) {
return user.get('entryPage') === location.pathname ? "google_bounce" : "google_not_bounce";
}
return "not_from_google";
Hi @bkrane2 ,
These scripts run on the edge (server-side), so tracking browser behaviors (like scroll or time on page) needs to be collected client-side and passed into Target as profile parameters using targetPageParams() or adobe.target.trackEvent().
So each use case requires:
User spent more than 60 seconds on homepage.com/product
Client-side JS (placed on /product page):
setTimeout(() => {
adobe.target.trackEvent({
"mbox": "time_on_product_page",
"params": {
"time60": "true"
}
});
}, 60000); // 60 seconds
if (mbox.name == "time_on_product_page" && mbox.param("time60") == "true") {
profile.time60OnProductPage = true;
}
return profile.time60OnProductPage || false;
/product
page):
window.addEventListener('scroll', function() {
let scrollTop = window.scrollY;
let docHeight = document.documentElement.scrollHeight - window.innerHeight;
let scrollPercent = (scrollTop / docHeight) * 100;
if (scrollPercent >= 50 && !window.hasSentScroll) {
window.hasSentScroll = true;
adobe.target.trackEvent({
mbox: "scrolled_product_page",
params: {
scrolled50: "true"
}
});
}
});
if (mbox.name == "scrolled_product_page" && mbox.param("scrolled50") == "true") {
profile.scrolled50OnProduct = true;
}
return profile.scrolled50OnProduct || false;
This requires tracking:
Referrer: passed from the initial page.
Bounce: usually defined as only one pageview.
// On landing page:
if (document.referrer.includes("google.com")) {
adobe.target.trackEvent({
mbox: "landing_page_referrer",
params: {
referrer: "google"
}
});
}
// Optional: Use `beforeunload` to detect bounce (not fully reliable)
window.addEventListener('beforeunload', function () {
adobe.target.trackEvent({
mbox: "bounce_detected",
params: {
bounced: "true"
}
});
});
if (mbox.name == "landing_page_referrer" && mbox.param("referrer") == "google") {
profile.referredByGoogle = true;
}
if (mbox.name == "bounce_detected" && mbox.param("bounced") == "true") {
profile.bounced = true;
}
return (profile.referredByGoogle && profile.bounced) || false;
Thank you for the help, I really appreciate it... One quick follow up question. For #2 & #3 do I add that client side code snippet in a Target activity in the <head> under 'Modifications'? Or do these snippets need to be added to the base page code outside of Adobe?
Thanks again!
Views
Replies
Total Likes
@bkrane2 you can refer below post list of examples
Views
Replies
Total Likes
Views
Likes
Replies