We have a Magento e-commerce website with about 2500 products, and I would like to track which products our known leads are looking at.
To give some context, we are creating a lead scoring programme for repeat customers, and need this information for two reasons:
Originally I was thinking I would be able to use the page url to filter this, as normally the url contains the SKU. However, I have since found out that this isn't always the case. Because its an e-commerce site with a deep category structure, there may be several urls for the same product, depending on how the customer arrived at the product page (directly from the search engine, through the category structure, from site search etc). And the SKU isn't always included.
Instead, can Marketo/Munchkin identify the actual product SKU (an example of how it appears in the source, with SKU highlighted, below) and then record this against the lead?
<div class="product attribute sku">
<strong class="type">Product code</strong> <div class="value" itemprop="sku">
THIS-IS-THE-SKU </div>
</div>
I am out of my depth here, so hopefully the question makes sense. If this is not possible, is there another way we can achieve this?
Solved! Go to Solution.
var sKUInPage = document.querySelector(".product.attribute.sku .type .value[itemprop='sku']").textContent.trim();
var currentLoc = document.createElement("a");
currentLoc.href = document.location.href;
currentLoc.search = "ProductSKU=" + encodeURIComponent(sKUInPage) + ( currentLoc.search ? "&" + currentLoc.search.substring(1) : "" );
history.replaceState && history.replaceState({},"",currentLoc.href);
N.B. history.replaceState doesn't exist in IE 8-9. If you must support those browsers, then you need to use the #hash (fragment) instead.
TBH I don't know if there is best practice for this sort of thing
None at all, the order of query params doesn't matter (unless a back-end server is trying to break stuff).
Munchkin doesn't try to identify anything within page elements.
Of course if this fragment (called microdata) is always present in the page, it's easy to find. And in theory you could append it to the URL before loading Munchkin.
var sKUInPage = document.querySelector(".product.attribute.sku .type .value[itemprop='sku']").textContent.trim();
Hi Sanford,
Thanks for your response... but I'm not a developer. Please could you help with some more detail before I share this with my web dev team?
1 - Does the above JS just find the microdata, is it appending it to the URL as well? If not, how do I append it to the URL?
2 - Where should this be added to the page HTML - I'm guessing inside <head> but after the munchkin snippet?
Thanks again
1 - Does the above JS just find the microdata, is it appending it to the URL as well? If not, how do I append it to the URL?
It finds the value and sets a JS variable. Where do you want to append it to the URL (be specific)?
2 - Where should this be added to the page HTML - I'm guessing inside <head> but after the munchkin snippet?
Definitely not after the Munchkin embed code! It must be before the embed code, so that when Munchkin checks the current location the SKU is already present.
It finds the value and sets a JS variable. Where do you want to append it to the URL (be specific)?
I think immediately after the base url, as the first parameter. So www.ourwebsite.com/category/productpage&ProductSKU=ABC123&allotherparameters. Does that answer your question? (TBH I don't know if there is best practice for this sort of thing).
Definitely not after the Munchkin embed code! It must be before the embed code, so that when Munchkin checks the current location the SKU is already present.
Now you say it... that's kind of obvious. Thanks!
var sKUInPage = document.querySelector(".product.attribute.sku .type .value[itemprop='sku']").textContent.trim();
var currentLoc = document.createElement("a");
currentLoc.href = document.location.href;
currentLoc.search = "ProductSKU=" + encodeURIComponent(sKUInPage) + ( currentLoc.search ? "&" + currentLoc.search.substring(1) : "" );
history.replaceState && history.replaceState({},"",currentLoc.href);
N.B. history.replaceState doesn't exist in IE 8-9. If you must support those browsers, then you need to use the #hash (fragment) instead.
TBH I don't know if there is best practice for this sort of thing
None at all, the order of query params doesn't matter (unless a back-end server is trying to break stuff).
Perfect, thanks Sanford, appreciate your help with this. And no, we don't bother to support older than IE 11.
Hi Barry! If you have custom development resources, another option may be to create a Marketo custom object for the orders/SKUs. It's more technically involved, but could be a good option. More information is here: Understanding Marketo Custom Objects - Marketo Docs - Product Documentation .
You can't create anything if you don't know the SKU they visited first.
Hi Maria,
Thanks for your comment - as Sanford says I need to know the SKU first - but after that, I will certainly be using either CO's or CA's to store this information, as per my question here: Whats the best way to store order, quote and product information in Marketo. If you have any advice on this, I'd appreciate it if you could comment on that question. Thanks again.