Skip to content

Instantly share code, notes, and snippets.

View marcusRB's full-sized avatar
🎯
Focusing

Marco marcusRB

🎯
Focusing
View GitHub Profile
@marcusRB
marcusRB / EEC_productID for GTM
Created October 14, 2018 10:07
EEC_productID for GTM
/* EEC ProductsIDs - Custom JS for GTM - update 09-2018 MR//PD
- EEC dataExtract for FBads, ADW, and 3rdParty
- This function create new array and interact with it
- Combine differents cases, when exist '/p/' product URL, '/c/' category URL, '/search/' searchQuery in URL, or event 'addToCart'
-
*/
function() {
try{
@marcusRB
marcusRB / EEC_categoryName for Tag Manager
Created October 14, 2018 10:04
EEC_categoryName for Tag Manager
* EEC CategoryName - Custom JS for GTM - update 09-2018 MR//PD
- EEC dataExtract for FBads, ADW, and 3rdParty
- This function create new array and interact with dataLayer
- {{dlv - pageHierarchy}} is a custom variable, or dataLayer extract categories levels as Array
*/
function() {
try{
if({{Page Path}}.indexOf('/p/') != -1){
@marcusRB
marcusRB / EEC_productName customVar
Created October 14, 2018 10:00
EEC_productName
/* EEC ProductsName - Custom JS for GTM - update 09-2018 MR//PD
- EEC dataExtract for FBads, ADW, and 3rdParty
- This function create new array and interact with it
- Combine differents cases, when exist '/p/' product URL, '/c/' category URL, '/search/' searchQuery in URL, or event 'addToCart'
-
*/
function() {
try{
@marcusRB
marcusRB / EEC_productPrice
Created October 14, 2018 09:49
EEC_productPrice from DLV detailProducts
/*EEC productPrice from DLV detailProducts - update 09-2018 MR//PD
- dataExtract for FBads, ADW, and 3rdParty
- create new ARRAY with floatValues per each prods price
*/
function() {
try{
var products = {{dlv - ecommerce.detail.products}};
return parseFloat(products.map(function(prod) { return prod.price; }).join());
} catch(e){
@marcusRB
marcusRB / FBads4GTM_viewContent_example.js
Last active October 14, 2018 09:46
ProductDetails as ViewContent for custom tag of Facebook Ads on Google Tag Manager
/* ProductDetails as ViewContent for Google Tag Manager - Update 10.2018 MR//PD
Trigger: Service webpage or Product webpage page loaded
Remember: Set Tag Sequencing load before main pageView FBads tag
*/
<script>
fbq('track', 'ViewContent', {
value: {{cJS - EEC - product.detail.price}}, //product detail Price as FLOAT
currency: 'EUR', // currency as STRING
@marcusRB
marcusRB / FBads4GTM_mainPixel_example.js
Created October 14, 2018 08:41
FBads for Google Tag Manager - pixelTag example
/* mainFacebookADS pixel code customized for Google Tag Manager - Update 10.2018 MR//PD
Trigger: tag works in all PageViews or custom webpages
Remember: Put outside noscript PIXEL_code into custom IMG
*/
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
@marcusRB
marcusRB / gtm-new-datalayer-gdpr
Created July 1, 2018 14:56
new dataLater for GDPR law - Google Tag Manager
<script id = "Cookiebot" src = "https://consent.cookiebot.com/uc.js?cbid={{CookieBotId}}" type = "text / javascript"> </ script>
<script>
función CookiebotCallback_OnAccept () {
if ((Cookiebot.consent.preferences) && (CookieConsent.preferences {{}}! = "true"))
dataLayer.push ({ 'evento': 'cookieconsent_preferences'});
if ((Cookiebot.consent.statistics) && CookieConsent.statistics {{}}! = "true")
dataLayer.push ({ 'evento': 'cookieconsent_statistics'});
if ((Cookiebot.consent.marketing) && CookieConsent.marketing {{}}! = "true")
dataLayer.push ({ 'evento': 'cookieconsent_marketing'});
}
@marcusRB
marcusRB / gtm-datalayer-checkout-steps
Created June 30, 2018 15:42
Measuring Checkout Steps EEC dataLayer
<script>
/**
* A function to handle a click on a checkout button. This function uses the eventCallback
* data layer variable to handle navigation after the ecommerce data has been sent to Google Analytics.
*/
function onCheckout() {
dataLayer.push({
'event': 'checkout',
'ecommerce': {
'checkout': {
@marcusRB
marcusRB / gtm-datalayer-remove-from-to-cart
Created June 30, 2018 14:44
Remove a Product from to Shopping Cart EEC dataLayer
// Measure the removal of a product from a shopping cart.
dataLayer.push({
'event': 'removeFromCart',
'ecommerce': {
'remove': { // 'remove' actionFieldObject measures.
'products': [{ // removing a product to a shopping cart.
'name': 'Triblend Android T-Shirt',
'id': '12345',
'price': '15.25',
'brand': 'Google',
@marcusRB
marcusRB / gtm-datalayer-add-to-cart
Created June 30, 2018 14:42
Adding a Product to a Shopping Cart EEC dataLayer
// Measure adding a product to a shopping cart by using an 'add' actionFieldObject
// and a list of productFieldObjects.
dataLayer.push({
'event': 'addToCart',
'ecommerce': {
'currencyCode': 'EUR',
'add': { // 'add' actionFieldObject measures.
'products': [{ // adding a product to a shopping cart.
'name': 'Triblend Android T-Shirt',
'id': '12345',