Skip to content

Instantly share code, notes, and snippets.

@nikosantis
Last active May 6, 2022 16:32
Show Gist options
  • Save nikosantis/143c1e1e71950132b7bbc7ed647c0366 to your computer and use it in GitHub Desktop.
Save nikosantis/143c1e1e71950132b7bbc7ed647c0366 to your computer and use it in GitHub Desktop.
Dealer events
<!-- add more information to differentiate the dealer and phone type -->
<a
href="javascript:void(0)"
class="mostrar_elemento"
data-show="+56 2 29424282"
data-dealer="DECONTRACT"
data-phoneType="phone"
>Ver teléfono</a
>
<!-- add more information to differentiate the dealer and phone type -->
<a
href="javascript:void(0)"
class="mostrar_elemento"
data-show="+56 9 57012874"
data-dealer="DECONTRACT"
data-phoneType="mobile"
>Ver teléfono</a
>
<!-- add more information to differentiate the dealer and id for the anchor -->
<a href="https://wa.me/+56957012874" target="_blank" id="wspLink" data-dealer="DECONTRACT">Iniciar conversación</a>
<!-- add more information to differentiate the dealer and id for the anchor -->
<a href="http://decontract.cl/" target="_blank" id="dealerWebsite" data-dealer="DECONTRACT">decontract.cl/</a>
<script>
jQuery(document).ready(function () {
jQuery(".mostrar_elemento").on("click", function () {
// it could be verified if the phone is actually being displayed or not so as not to duplicate events
if (this.text === "Ver teléfono") {
var mostrar = jQuery(this).data("show");
jQuery(this).html(mostrar);
jQuery(this).attr("href", "tel:" + jQuery(this).data("show"));
dataLayer.push({
event: "viewPhone",
dealer: jQuery(this).data("dealer"),
phoneType: jQuery(this).data("phoneType")
});
} else {
// if the phone was already shown, fire a click event
dataLayer.push({
event: "clickPhone",
dealer: jQuery(this).data("dealer"),
phoneType: jQuery(this).data("phoneType")
});
}
});
// click event when conversation starts
jQuery("#wspLink").on("click", function () {
dataLayer.push({
event: "startingConversation",
dealer: jQuery(this).data("dealer")
});
});
// dealer website click event
jQuery("#dealerWebsite").on("click", function () {
dataLayer.push({
event: "dealerWebsiteClick",
dealer: jQuery(this).data("dealer")
});
});
});
</script>
<script>
// dealer form event
dataLayer.push({
event: "formSent",
formName: "dealerForm", // you can use formName or formId
formEmail: "email from form",
formPhone: "phone from form", // only if the phone is required in the form
formDealer: "dealer name"
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment