But when we check Klaviyo it never shows up. In the past when we created new tracks like this it worked and would just start populating data but for some reason it doesn’t this time around.
Kind Regards, Ian Hogers
Page 1 / 1
Hi @IanHogers,
Before you use _learnq.push, you need to define _learnq as follows:
var _learnq = _learnq || [];
If you add the above and the user has been cookied or identified, the event should show up in your Klaviyo account. You can learn more about Klaviyo’s APIs here.
Best,
Caroline
Hi @caroline ,
Thanks for your reply, We’ve got this already in there. Please see our snippet:
function pushViewedItems() { /** * Some functionality here for gathering data about the viewed product * ... code */ let viewed_items_construction = { "$value": viewed_list_value, // Total value of all the items in the stored_viewed_items array "Items": stored_viewed_items // stored_viewed_items is an array with [viewed_item] values }
// Doesn't work _learnq.push(['track', 'Viewed Multiple Products', viewed_items_construction]);
// Works _learnq.push(['track', 'Viewed Product', viewed_item]);
}
})
So the “Viewed Product” track push does work but the “Viewed Multiple Products” does not
Kind Regards, Ian Hogers
Hey @IanHogers ,
Do you happen to have a URL link to share that I could take a look at to debug?
One other thing to note is that Klaviyo doesn’t track anonymous behavior, so if you are not identified on the site, the activity can’t be tracked back to a profile. Here is a good article about who Klaviyo tracks. We basically need one of 3 things to happen in order to properly identify a user on the frontend to track data to a profile:
somebody fills out a Klaviyo form
somebody clicks on a Klaviyo email that goes to your site with the klaviyo.js tracking code on it
javascript written to execute and identify somebody via our javascript API fires to track somebody’s email address
You can always check to see if you are currently identified by popping open the console and typing:
_learnq.identify()
if $email shows up, then you’re successfully identified. If just referrer info shows up, you’re not. A quick way to identify yourself would then be to simply add a URL parameter to the page you’re on (as long as it has klaviyo.js on the page somewhere) and add in https://website.com?utm_email=youremail@domain.com and hit Return to refresh.
Hopefully this helps. If the steps to identify yourself don’t work, please feel free to shoot over the link of the page you’re working on so I can take a look (via DM or on here, wherever you’re comfortable)
Please see the code snippet in the element inspector, search for
pushViewedItems()
You can see at the end of the snippet: “Viewed Product” and “Viewed Multiple Products”
Thanks for helping out.
Kind Regards, Ian Hogers
Hi Ian,
Yep, so my initial hunch was correct, you have to be identified by the browser in order to have this event show up on a profile’s timeline in Klaviyo. Here’s what I did to test this:
In Klaviyo, I can now see on my profile that the Wishlist event was sent to my profile
The snippet appears to be working, you likely just weren’t identified by the browser when you were testing:
To check if you’re identified you can type:
_learnq.identify()
into the console when you’re on the site and if you don’t see $email returned, you’ll know that you’re not identified.
Hi Connor,
Thanks again for the reply,
The issue is not happening with the add to wishlist but with “Viewed Multiple Products”.
It’s just not showing up in klaviyo, “Viewed Product” works, but “Viewed Multiple Products” doesn’t.
Kind Regards, Ian
Hey @IanHogers , my bad! I misread your original post.
From what it looks like, this is an issue with the _learnq function fully loading after the code to push the Viewed Items to Klaviyo gets called. Oddly enough, the next line is able to run, but this is definitely some weird DOM timing issue. Here’s what I get when I put a debugger on the line after you call:
This just means that _learnq is being initialized as an empty array and that klaviyo.js hasn’t loaded fully when this function is called.
All I did to fix the issue was:
Moved the declaration of _learnq outside of the $document.ready function to the top of the script above the line var viewed_items_list = []
swapped out your $(document).ready(function(){ }) with window.onload = function(){}
These two things seemed to fix the _learnq timing issue as with those changes above, we get the following in the console:
You should be able to see my profile with the Viewed Multiple Products event on it now (connor+kltest@gmail.com). Once you make the two changes I mentioned above, you should be good to go!
Hey @cbarley ! That’s it!
silly HTML and JavaScript!
Thanks heaps. Can you mark that last reply as the solution instead? thanks!
@IanHogers will do! and no problem, happy to help
My personal experience as of 3/7/2023 is that using
_learnq.identify()
after using ?utm_email=(email address) did not return a field $email and tracking still worked for me.
Just thought I’d share my experience here in case someone else experienced the same thing