Highlighted

Custom goal triggering via Javascript

Avatar

Avatar

abbyd77023085

Avatar

abbyd77023085

abbyd77023085

12-09-2017

Is there away somehow i can tirgger a goal via javascript API by writing custom javascript.

Some thing like

$(".css-class").click(function(){

    //trigger click goal here

   //window.trigger('goal-name');

});

Replies

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

19-09-2017

yes thats possible. how have you implemented Adobe Target

via mbox or at.js?

Highlighted

Avatar

Avatar

abbyd77023085

Avatar

abbyd77023085

abbyd77023085

19-09-2017

Hi sabahatu,

Thanks for replying back.

As i didn’t setup the target for the website. I cannot say for sure.

Client has already set it up. I got the access later.

I think its at.js,

cuz the elements in page have class like “at-element-marker”

and also “at-element-click-tracking” (when click goal is added via “Goal & Settings”)

But when i check the Setup=> Implementation, mbox.js is selected.

To add up,

I have already tried following

<script>

$('a').click(function(){

  adobe.target.trackEvent({'mbox’:’quicklinkclick’})

});

</script>

and added conversion goal to view mbox “quicklinkclick”;

when i check console log in chrome, i got following:

VM768 satellite-59b9eb0164746d4b1b00b18b.js:18

AT: Track event request failed {mbox: "quicklinkclick", params: {…}, timeout: 15000, success: ƒ, error: ƒ} {status: "error", error: "abort"}

Highlighted

Avatar

Avatar

sabahatu1546489

Avatar

sabahatu1546489

sabahatu1546489

20-09-2017

you are on a right track.
I assume you first created this mbox "quicklinkclick" through console and secondly under metrics you selected "viewed an mbox" (Not clicked on mbox)

cheers,

Sabahat

Highlighted

Avatar

Avatar

arturc85303583

Employee

Avatar

arturc85303583

Employee

arturc85303583
Employee

08-11-2017

abbyd77023085​, modern browsers like Chrome and FireFox try to optimize resource usage as much as possible, so when we use code like this:

<script>

$('a').click(function(){

  adobe.target.trackEvent({mbox:'quicklinkclick'})

});

</script>

What happens behind the scenes is the following:

- User clicks the link
- Click event listener is executed and a click tracking request is fired
- At the same time browser sees that he has to load a new page, because user clicked on a link, so Chrome and FireFox will "cancel" the click tracking request and that's why we see the "abort" message being logged

To fix this we'll have to do the following:

- Prevent default click handling

- Load the page referenced by the link manually

The code could look like this:

<script>

$('a').click(function(e){

  e.preventDefault();

  adobe.target.trackEvent({

    mbox:'quicklinkclick',

    success: function() {

      location.href = $(a).attr('href');

    },

    error: function() {

      location.href = $(a).attr('href');

    },

    timeout: 500

  });

});

</script>

NOTE: it is important to use a timeout, so we don't block the page navigation for too long. Also it is important to use success and error callbacks to make sure that we navigate away ONLY when Target request succeeded or failed.