Я создал блок, нацеленный на тело, чтобы код проверил URL -адрес при открытии магазина, и цель состоит больше не в URL. < /p>
Вот мой текущий блок: < /p>
{% comment %}
Embed to provide global js to check the utms when user enters shop
{% endcomment %}
const newAttributes = {{ cart.attributes }}
if (!newAttributes.UTMs) newAttributes.UTMs = []
const urlParams = new URLSearchParams(window.location.search);
for (const [key, value] of urlParams.entries()) {
if (key === "utm_source" && !newAttributes.UTMs.includes(value)) {
newAttributes.UTMs.push(value)
console.log(newAttributes, 'other attributes')
}
}
fetch(window.Shopify.routes.root + 'cart/update.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
attributes: newAttributes
})
})
.then(function(res) {
return res.json();
})
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.error(err);
});
{% schema %}
{
"name": "UtmCheck",
"target": "body",
"settings": []
}
{% endschema %}```
and the error I keep getting is saying `Uncaught SyntaxError: Unexpected token '=>'`
Подробнее здесь: https://stackoverflow.com/questions/794 ... -extension
Как я могу хранить значения UTM в тележек Shopify через расширение приложения темы? ⇐ Javascript
Форум по Javascript
1739056766
Anonymous
Я создал блок, нацеленный на тело, чтобы код проверил URL -адрес при открытии магазина, и цель состоит больше не в URL. < /p>
Вот мой текущий блок: < /p>
{% comment %}
Embed to provide global js to check the utms when user enters shop
{% endcomment %}
const newAttributes = {{ cart.attributes }}
if (!newAttributes.UTMs) newAttributes.UTMs = []
const urlParams = new URLSearchParams(window.location.search);
for (const [key, value] of urlParams.entries()) {
if (key === "utm_source" && !newAttributes.UTMs.includes(value)) {
newAttributes.UTMs.push(value)
console.log(newAttributes, 'other attributes')
}
}
fetch(window.Shopify.routes.root + 'cart/update.js', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
attributes: newAttributes
})
})
.then(function(res) {
return res.json();
})
.then(function(result) {
console.log(result);
})
.catch(function(err) {
console.error(err);
});
{% schema %}
{
"name": "UtmCheck",
"target": "body",
"settings": []
}
{% endschema %}```
and the error I keep getting is saying `Uncaught SyntaxError: Unexpected token '=>'`
Подробнее здесь: [url]https://stackoverflow.com/questions/79424066/how-can-i-store-utm-values-in-the-shopify-cart-through-a-theme-app-extension[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия