Skip to content

Instantly share code, notes, and snippets.

@rgoytacaz
Last active January 25, 2019 02:49
Show Gist options
  • Save rgoytacaz/688131d05178614563f5e103f1b08ae6 to your computer and use it in GitHub Desktop.
Save rgoytacaz/688131d05178614563f5e103f1b08ae6 to your computer and use it in GitHub Desktop.
//marketingData Example
//vtexjs.checkout.orderForm.marketingData
//Example 1: GET UTMS FROM COOKIES OR EMPTY
utms = {
utmCampaign: (Cookies.get('IPS').indexOf('Campanha')!= -1 ? Cookies.get('IPS').split('Campanha=')[1].split('&')[0] : "" ),
utmMedium: (Cookies.get('IPS').indexOf('Midia')!= -1 ? Cookies.get('IPS').split('Midia=')[1].split('&')[0] : "" ),
utmSource: (Cookies.get('IPS').indexOf('Parceiro')!= -1 ? Cookies.get('IPS').split('Parceiro=')[1].split('&')[0] : "" ),
utmiCampaign: (Cookies.get('ISICI').indexOf('InternalCampaign')!= -1 ? Cookies.get('ISICI').split('InternalCampaign=')[1].split('&')[0] : "" ),
utmiPart: (Cookies.get('ISICI').indexOf('InternalPart')!= -1 ? Cookies.get('ISICI').split('InternalPart=')[1].split('&')[0] : "" )
}
//Example 2: GET UTMS FROM CURRENT ORDERFORM
//YOU CAN CHECKOUT VTEXJS.CHECKOUT.ORDERFORM.MARKETINGDATA
utms = {
utmCampaign: vtexjs.checkout.orderForm.marketingData.utmCampaign,
utmSource: vtexjs.checkout.orderForm.marketingData.utmSource
}
//EXAMPLE 3: SETTING YOUR OWN
utms = {
coupon: "MYCOUPON",
marketingTag: [],
utmCampaign: "",
utmMedium: "",
utmSource: "",
utmiCampaign: "",
utmiPart: ""
}
//EXAMPLE 4: EMPTY MARKETING DATA
utms = {
coupon: "",
marketingTag: [],
utmCampaign: "",
utmMedium: "",
utmSource: "",
utmiCampaign: "",
utmiPart: ""
}
//Execute after item was added to the cart.
vtexjs.checkout.sendAttachment('marketingData', utms);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment