ovipreneur

gsf conversion

Dec 27th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.19 KB | None | 0 0
  1. <script>
  2. {% assign gsf_product_data_array = '' %}
  3. {% assign gsf_product = '' %}
  4. {% if template contains 'product' %}
  5. var gsf_conversion_data = {page_type : 'product', event : 'view_item', data : {product_data : [{variant_id : {{ product.selected_or_first_available_variant.id }}, product_id : {{ product.id }}, name : "{{ product.title | strip_html | escape }}", price : {%if shop.money_format contains 'comma_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}"{%endif%}, currency : "{{ shop.currency }}", sku : "{{ product.selected_or_first_available_variant.sku }}", brand : "{{ product.vendor }}", variant : "{{ product.selected_or_first_available_variant.title | strip_html | escape }}", category : "{{ product.type | strip_html | escape }}"}], total_price : {%if shop.money_format contains 'comma_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}"{%endif%}}};
  6. {% elsif template contains 'cart' and cart.item_count > 0 %}
  7. var gsf_conversion_data = {page_type : 'cart', event : 'add_to_cart', data : {product_data : [{% for item in cart.items %}{variant_id : {{ item.variant_id }}, product_id : {{ item.product_id }}, name : "{{ item.title | strip_html | escape }}", price : {%if shop.money_format contains 'comma_separator'%}"{{ item.variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ item.variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ item.variant.price | money_without_currency | remove: ',' }}"{%endif%}, currency : "{{ shop.currency }}", sku : "{{ item.variant.sku }}", brand : "{{ item.vendor }}", variant : "{{ item.variant.title | strip_html | escape }}", category : "{{ item.product.type | strip_html | escape }}"}{% if forloop.last != true %}, {% endif %}{% endfor %}], total_price : {%if shop.money_format contains 'comma_separator'%}"{{ cart.total_price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ cart.total_price | money_without_currency | remove: "'" }}"{%else%}"{{ cart.total_price | money_without_currency | remove: ',' }}"{%endif%}}};
  8. {% elsif template contains 'index' %}
  9. {% if collections.best_selling.products.size > 0 %}{% assign gsf_product = collections.best_selling.products | sort: 'best-sellers' %}
  10. {% elsif collections.best-selllers.products.size > 0 %}{% assign gsf_product = collections.best-selllers.products | sort: 'best-sellers' %}
  11. {% else collections.all.products.size > 0 %}{% assign gsf_product = collections.all.products | sort: 'best-sellers' %}
  12. {% endif %}
  13. {% if gsf_product.size > 0 %}{% assign limit = gsf_product.size %}{% if limit > 2 %}{% assign limit = 2 %}{% endif %}{% for product in gsf_product limit:limit %}{% capture gsf_product_data_array %}{{ gsf_product_data_array }}{variant_id : {{ product.selected_or_first_available_variant.id }}, product_id : {{ product.id }}, name : "{{ product.title | strip_html | escape }}", price : {%if shop.money_format contains 'comma_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}"{%endif%}, currency : "{{ shop.currency }}", sku : "{{ product.selected_or_first_available_variant.sku }}", brand : "{{ product.vendor }}", variant : "{{ product.selected_or_first_available_variant.title | strip_html | escape }}", category : "{{ product.type | strip_html | escape }}"}{% if forloop.last != true %}, {% endif %}{% endcapture %}{% assign get_price = product.selected_or_first_available_variant.price %}{% assign total_value_arr = total_value_arr | plus: get_price %}{% endfor %}
  14. var gsf_conversion_data = {page_type : 'home', event : 'page_view', data : {product_data : [{{ gsf_product_data_array }}], total_price :{%if shop.money_format contains 'comma_separator'%}"{{ total_value_arr | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ total_value_arr | money_without_currency | remove: "'" }}"{%else%}"{{ total_value_arr | money_without_currency | remove: ',' }}"{%endif%}}};
  15. {% else %}
  16. var gsf_conversion_data = {page_type : 'home', event : 'page_view', data : {product_data : [], total_price : 0}};
  17. {% endif %}
  18. {% elsif template contains 'collection' and collection.products.size > 0%}
  19. {% assign limit = collection.products.size %}{% if limit > 4 %}{% assign limit = 4 %}{% endif %}{% for product in collection.products limit:limit %}{% capture gsf_product_data_array %}{{ gsf_product_data_array }}{variant_id : {{ product.selected_or_first_available_variant.id }}, product_id : {{ product.id }}, name : "{{ product.title | strip_html | escape }}", price : {%if shop.money_format contains 'comma_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ product.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}"{%endif%}, currency : "{{ shop.currency }}", sku : "{{ product.selected_or_first_available_variant.sku }}", brand : "{{ product.vendor }}", variant : "{{ product.selected_or_first_available_variant.title | strip_html | escape }}", category : "{{ product.type | strip_html | escape }}"}{% if forloop.last != true %}, {% endif %}{% endcapture %}{% assign get_price = product.selected_or_first_available_variant.price %}{% assign total_value_arr = total_value_arr | plus: get_price %}{% endfor %}
  20. var gsf_conversion_data = {page_type : 'category', event : 'view_item_list', data : {product_data : [{{ gsf_product_data_array }}], total_price :{%if shop.money_format contains 'comma_separator'%}"{{ total_value_arr | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ total_value_arr | money_without_currency | remove: "'" }}"{%else%}"{{ total_value_arr | money_without_currency | remove: ',' }}"{%endif%}}};
  21. {% elsif template contains 'search' and search.performed and search.results != empty %}
  22. {% assign limit = search.results_count %}{% if limit > 4 %}{% assign limit = 4 %}{% endif %}{% for item in search.results limit:limit %}{% capture gsf_product_data_array %}{{ gsf_product_data_array }}{variant_id : {{ item.selected_or_first_available_variant.id }}, product_id : {{ item.id }}, name : "{{ item.title | strip_html | escape }}", price : {%if shop.money_format contains 'comma_separator'%}"{{ item.selected_or_first_available_variant.price | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ item.selected_or_first_available_variant.price | money_without_currency | remove: "'" }}"{%else%}"{{ item.selected_or_first_available_variant.price | money_without_currency | remove: ',' }}"{%endif%}
  23. , currency : "{{ shop.currency }}", sku : "{{ item.selected_or_first_available_variant.sku }}", brand : "{{ item.vendor }}", variant : "{{ item.selected_or_first_available_variant.title | strip_html | escape }}", category : "{{ item.type }}"}{% if forloop.last != true %}, {% endif %}{% endcapture %}{% assign get_price = item.selected_or_first_available_variant.price %}{% assign total_value_arr = total_value_arr | plus: get_price %}{% endfor %}
  24. var gsf_conversion_data = {page_type : 'searchresults', event : 'view_search_results', data : {product_data : [{{ gsf_product_data_array }}], total_price :{%if shop.money_format contains 'comma_separator'%}"{{ total_value_arr | money_without_currency | replace:',','-' | replace:'.',',' | replace:'-','.' | remove: ',' }}"{%elsif shop.money_format contains 'apostrophe_separator'%}"{{ total_value_arr | money_without_currency | remove: "'" }}"{%else%}"{{ total_value_arr | money_without_currency | remove: ',' }}"{%endif%}}};
  25. {% else %}
  26. var gsf_conversion_data = {page_type : '', event : '',};
  27. {% endif %}
  28. </script>
Advertisement
Add Comment
Please, Sign In to add comment