Artikelen over: AdPage Tagging

DataLayer + Tagging toevoegen aan Lightspeed C-series.

Om het meten van events zo optimaal mogelijk te maken is een DataLayer van essentieel belang. Daarom hebben we een eigen DataLayer ontwikkeld voor Lightspeed C-series. Volg onderstaande stappen om dit te realiseren in jouw Lightspeed shop:

Ga naar settings > web extra's. Plak vervolgens bij CUSTOM JS, het volgende script onder het AdPage Tagging script. ||| Zorg ervoor dat je https://tagging.jouwdomeinnaam.nl vervangt door je eigen AdPage Tagging subdomeinnaam.

CUSTOM JS

<script src="https://tagging.jouwdomeinnaam.nl/lightspeed-c-series-minified.js"></script>


Bij TRACKING voeg je het volgende script toe:

TRACKING TOEVOEGEN

<script>  
  var taggingUserIdCookieName = "tagging_user_id";

  function getCookie(name) {
    const cookies = document.cookie.split("; ");
    for (const cookie of cookies) {
      const [cookieName, cookieValue] = cookie.split("=");
      if (cookieName === name) {
        return decodeURIComponent(cookieValue);
      }
    }
    return null;
  }

  function generateMarketingObject() {
    const cookieData = {};
    const analyticsCookies = {};
    const sessionId = {};
    const sessionCount = {};

    // Add all cookies that start with _ga_
    const cookies = document.cookie.split("; ");
    for (const cookie of cookies) {
      const cookieObj = cookie.split("=");
      if (cookieObj[0].startsWith("_ga_")) {
        analyticsCookies[cookieObj[0]] = cookieObj[1];
        sessionId[cookieObj[0]] = cookieObj[1].split(".")[2];
        sessionCount[cookieObj[0]] = cookieObj[1].split(".")[3];
      }
    }

    cookieData.user_id = getCookie(taggingUserIdCookieName);
    cookieData._ga = getCookie("_ga");
    cookieData._fbp = getCookie("_fbp");
    cookieData._fbc = getCookie("_fbc");

    let clientId = "";

    if (getCookie("_ga")) {
      clientId = getCookie("_ga");
      const clientIdParts = clientId.split(".");
      clientId = clientIdParts[2] + "." + clientIdParts[3];
    }

    cookieData.client_id = clientId;
    cookieData.session_id = sessionId;
    cookieData.session_count = sessionCount;
    return cookieData;
  };

  window.dataLayer.push({ ecommerce: null });
  window.dataLayer.push({
    event: "trytagging_purchase",
    ecommerce: {
      transaction_id: "{{ order.information.number }}",
      value: "{{ order.information.price_incl }}",
      tax: "{{ order.information.price_tax }}",
      shipping: "{{ order.information.shipping_price }}",
      currency: "{{ order.information.currency }}",
      items: [
        {% for item in order.products %}
          {
            item_id: "{{ item.variant_id }}",
            item_name: "{{ item.title }}",
            price: "{{ item.price_incl }}",
            quantity: "{{ item.quantity }}",
            item_brand: "{{ item.brand }}",
            item_variant: "{{ item.variant }}",
          },
        {% endfor %}
      ],
    },
    user_data: {
      customer_id: "{{ order.customer.id }}",
      billing_first_name: "{{ order.customer.firstname }}",
      billing_last_name: "{{ order.customer.fulllastname }}",
      billing_address: "{{ order.billing.address }}",
      billing_postcode: "{{ order.billing.zipcode }}",
      billing_country: "{{ order.billing.country }}",
      billing_state: "{{ order.billing.region }}",
      billing_city: "{{ order.billing.city }}",
      billing_email: "{{ order.customer.email }}",
      billing_phone: "{{ order.customer.phone }}",
      shipping_first_name: "{{ order.shipping.attention }}",
      shipping_last_name: "{{ order.customer.fulllastname }}",
      shipping_company: "{{ order.shipping.company }}",
      shipping_address: "{{ order.shipping.address }}",
      shipping_postcode: "{{ order.shipping.zipcode }}",
      shipping_country: "{{ order.shipping.country }}",
      shipping_state: "{{ order.shipping.region }}",
      shipping_city: "{{ order.shipping.city }}",
      shipping_phone: "{{ order.customer.mobile }}",
    },
    marketing: generateMarketingObject(),
  });
</script>

Bijgewerkt op: 31/08/2023

Was dit artikel nuttig?

Deel uw feedback

Annuleer

Dankuwel!