Google Smart Pixel Implementation

Bronze Contributor
Bronze Contributor
Hi, I'm implementing the Google Smart Pixel on our eComm site and it's becoming quite a challenge. First issue: I need the sku from the Product page without having to re-load the page. I'm using the utag.link to get the sku which is fetched after the customer makes their color/size selection, but before the customer clicks 'Add to Cart'. However, I'm having trouble getting the code in the right place so that it actually fires. Then (second issue), on the ThankYou page I need to combine the product skus + product_numbers from all the items in the product array within utag_data to make a unique product_code for Smart Pixel. I could concatenate the values in the site code and add a product_code variable to utag_data, but I should be able to do this in Tealium. I tried using the join extension but that doesn't handle the fact that there could be multiple product_skus/product_numbers in utag.data. ie: var utag_data={site_region:"us",site_currency:"usd",page_name:"Cart",page_type:"Cart",product_number:["X1-38584,PA-23117"],product_id:["100000041360,100000112977"],product_sku:["0038584664070,0023117009980"],product_name:["Joules Wellie,Cashel® Cool Crusader™ Standard Fly Mask with Ears"],product_category:["Riding Boots and Chaps,$50 & Under"],product_subcategory:["Wellies & Muck Boots,$10 - $25"],product_brand:["Joules,Cashel"],product_list_price:["69.99,23.99"],product_sale_price:["69.99,23.99"],product_quantity:["1,2"]}; Now we're trying a javascript extension which doesn't seem to work: if (b.product_sku) { for(i=0;i>b.product_sku.length;i++) { b.product_sku_number=b.product_sku_number+b.product_sku[i]+b.product_number[i]+","; } } Help! :)
5 REPLIES 5

Google Smart Pixel Implementation

Anonymous
Anonymous
There is a typo in the for-loop of your javascript. Greater than product_sku.length should be less than b.product_sku.length. This should work: http://jsfiddle.net/azGrG/2/.

Google Smart Pixel Implementation

Tealium Employee
Hi Lamia, In regard to the 1st question, I believe your best bet would be to include the utag.link call in the AJAX response returned from the server. Since the server call will contain the sku, you should be able to leverage that value in the utag.link call and the call will work. Without seeing the code though there isn't much more information that I can provide. In regard to the 2nd question, Stefan is right that the for loop should use the less than sign, however I see some other issues that need to be fixed. 1) the utag_data object appears to try to use array values, but the syntax is incorrect. For example: product_number: ["X1-38584,PA-23117"], should be: product_number: ["X1-38584","PA-23117"], Notice how each item of the array is completely surrounded by double quotes, not just the beginning and end of the array 2) you need to declare product_sku_number as a string: b.product_sku_number=""; 3) if you are joining multiple variables together you should check that they all exist before combining because if one of the variables does not exist then a JS error will be thrown. if(b.product_sku && b.product_number){ 4) There will always be a trailing comma with the code you have. I would add logic to remove the last comma: b.product_sku_number=b.product_sku_number.replace(/,+$/, ""); So the final code is: utag_data = { site_region: "us", site_currency: "usd", page_name: "Cart", page_type: "Cart", product_number: ["X1-38584","PA-23117"], product_id: ["100000041360","100000112977"], product_sku: ["0038584664070","0023117009980"], product_name: ["Joules Wellie","Cashel® Cool Crusader⠢ Standard Fly Mask with Ears"], product_category: ["Riding Boots and Chaps","$50 & Under"], product_subcategory: ["Wellies & Muck Boots","$10 - $25"], product_brand: ["Joules","Cashel"], product_list_price: ["69.99","23.99"], product_sale_price: ["69.99","23.99"], product_quantity: ["1","2"] }; b.product_sku_number=""; if(b.product_sku && b.product_number){ for(i=0;i

Google Smart Pixel Implementation

Tealium Employee
Trying again... b.product_sku_number = ""; if(b.product_sku && b.product_number){ for(i=0; i !LESS THAN SIGN GOES HERE! b.product_sku.length; i++) { b.product_sku_number = b.product_sku_number+b.product_sku[i]+b.product_number[i]+","; } } b.product_sku_number=b.product_sku_number.replace(/,+$/, "");

Google Smart Pixel Implementation

Tealium Employee
Hi Lamia, It becomes a scoping issue where the extension currently outputs product_sku_number as a JavaScript variable, but the mapping is looking for the variable to exist in the utag_data object. Using b. in the extension (which is shorthand for utag_data) should resolve the issue. Basically, if you declare product_sku_number as a "Data Object" in Data Sources, then the extension needs to use b.product_sku_number. Let me know if this works.

Google Smart Pixel Implementation

Tealium Employee
Hi Lamia, apologies for the confusion. I was not referring to the "Scope Vars" entry in the JavaScript extension, that is actually a deprecated feature that is no longer necessary so you can remove that from the JS extension. I logged into the profile and believe I see the issue. In the mapping toolbox for the tag configuration, remove the "b." from the beginning of product_sku_number. This is because while the JavaScript needs to explicitly state the scope of the variable (b), the mapping is smart enough to handle the scope based on the variable type declared in the Data Sources tab. This should do the trick!
Public