Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- jQuery(function($) {
- tvc_lc="SGD";
- homepage_json_ATC_link=[];
- tvc_fp=[];
- tvc_rcp=[];
- tvc_rdp=[];
- prodpage_json_ATC_link=[];
- tvc_pgc=[];
- catpage_json_ATC_link=[];
- ga("require", "ec", "ec.js");
- ga("set", "&cu", tvc_lc);
- function t_products_impre_clicks(t_json_name,t_action){
- t_send_threshold=0;
- t_prod_pos=0;
- t_json_length=Object.keys(t_json_name).length;
- for(var t_item in t_json_name) {
- t_send_threshold++;
- t_prod_pos++;
- ga("ec:addImpression", {
- "id": t_json_name[t_item].tvc_i,
- "name": t_json_name[t_item].tvc_n,
- "category": t_json_name[t_item].tvc_c,
- "price": t_json_name[t_item].tvc_p,
- "position": t_json_name[t_item].tvc_po,
- });
- if(t_json_length > 6 ){
- if((t_send_threshold%6)==0){
- t_json_length=t_json_length-6;
- ga("send", "event", "Enhanced-Ecommerce","load","product_impression_"+t_action , {"nonInteraction": 1});
- }
- }else{
- t_json_length--;
- if(t_json_length==0){
- ga("send", "event", "Enhanced-Ecommerce","load", "product_impression_"+t_action, {"nonInteraction": 1});
- }
- }
- }
- }
- //function for comparing urls in json object
- function prod_exists_in_JSON(t_url,t_json_name,t_action){
- if(t_json_name.hasOwnProperty(t_url)){
- t_call_fired=true;
- ga("ec:addProduct", {
- "id": t_json_name[t_url].tvc_i,
- "name": t_json_name[t_url].tvc_n,
- "category": t_json_name[t_url].tvc_c,
- "price": t_json_name[t_url].tvc_p,
- "position": t_json_name[t_url].tvc_po,
- });
- ga("send", "event", "Enhanced-Ecommerce","click", "product_click_"+t_action, {"nonInteraction": 1});
- }else{
- t_call_fired=false;
- }
- return t_call_fired;
- }
- function prod_ATC_link_exists(t_url,t_ATC_json_name,t_prod_data_json,t_qty){
- t_prod_url_key=t_ATC_json_name[t_url]["ATC-link"];
- if(t_prod_data_json.hasOwnProperty(t_prod_url_key)){
- t_call_fired=true;
- // Enhanced E-commerce Add to cart clicks
- ga("ec:addProduct", {
- "id": t_prod_data_json[t_prod_url_key].tvc_i,
- "name": t_prod_data_json[t_prod_url_key].tvc_n,
- "category": t_prod_data_json[t_prod_url_key].tvc_c,
- "price": t_prod_data_json[t_prod_url_key].tvc_p,
- "quantity" : t_qty
- });
- ga("ec:setAction", "add");
- ga("send", "event", "Enhanced-Ecommerce","click", "add_to_cart_click",{"nonInteraction": 1});
- }else{
- t_call_fired=false;
- }
- return t_call_fired;
- }
- if(tvc_fp.length !== 0){
- t_products_impre_clicks(tvc_fp,"fp");
- }
- if(tvc_rcp.length !== 0){
- t_products_impre_clicks(tvc_rcp,"rp");
- }
- jQuery("a:not([href*=add-to-cart],.product_type_variable, .product_type_grouped)").on("click",function(){
- t_url=jQuery(this).attr("href");
- //home page call for click
- t_call_fired=prod_exists_in_JSON(t_url,tvc_fp,"fp");
- if(!t_call_fired){
- prod_exists_in_JSON(t_url,tvc_rcp,"rp");
- }
- });
- //ATC click
- jQuery("a[href*=add-to-cart]").on("click",function(){
- t_url=jQuery(this).attr("href");
- t_qty=$(this).parent().find("input[name=quantity]").val();
- //default quantity 1 if quantity box is not there
- if(t_qty=="" || t_qty===undefined){
- t_qty="1";
- }
- t_call_fired=prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_fp,t_qty);
- if(!t_call_fired){
- prod_ATC_link_exists(t_url,homepage_json_ATC_link,tvc_rcp,t_qty);
- }
- });
- tvc_smd={"tvc_wcv":"3.2.6","tvc_wpv":"4.9.2","tvc_eev":"1.2.1.2","tvc_cnf":{"t_ee":"yes","t_df":false,"t_gUser":false,"t_UAen":"no","t_thr":"6"}};
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment