Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Custom goal triggering via Javascript

abbyd77023085
Level 1
Level 1

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');

});

4 Replies
sabahatu1546489
Level 3
Level 3

yes thats possible. how have you implemented Adobe Target

via mbox or at.js?

abbyd77023085
Level 1
Level 1

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"}

sabahatu1546489
Level 3
Level 3

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

arturc85303583
Employee
Employee

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.