SOLVED

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

Go to solution
Barry_Dupont1
Level 3

Can Marketo identify specific information (i.e. product sku) on a webpage

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:

  1. Some products are higher value than others, so we want to vary the score depending on the product type.
  2. We want to compare this information with order/quotation data to make sure we do not create opportunities based on activity that is related to products they have already purchased.

(more info about that here)

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?

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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).

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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();
Barry_Dupont1
Level 3

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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.

Barry_Dupont1
Level 3

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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!

SanfordWhiteman
Level 10 - Community Moderator

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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).

Barry_Dupont1
Level 3

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

Perfect, thanks Sanford, appreciate your help with this. And no, we don't bother to support older than IE 11.

Mariah_Mattick
Level 4

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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 . 

Mariah Mattick
SanfordWhiteman
Level 10 - Community Moderator

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

You can't create anything if you don't know the SKU they visited first. 

Barry_Dupont1
Level 3

Re: Can Marketo identify specific information (i.e. product sku) on a webpage

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.