First time installing target v2.x + triggerview() function for SPA | Community
Skip to main content
Level 3
January 10, 2023
Solved

First time installing target v2.x + triggerview() function for SPA

  • January 10, 2023
  • 1 reply
  • 1260 views

I have successfully implemented step 1 below. I am trying to work out what is required for step 2.

 

I tried implementing this on a page, in the hope that it would then make this view (homeView) visible to me in the Target VEC... but it didn't. 

Am I overlooking something really simple here? Do I need to define the triggerView function somewhere? Thanks in advance.

<script>
window.addEventListener("load", (event) => {
adobe.target.triggerView("homeView");
});
</script>

 

With this, I am expecting to see the view appear in the modifications tab within Adobe Target using the VEC... But I dont.. 😞

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by MichaelWills

We were able to find a solution internally with our developers. The solution we came up with involves listening for 'any' clicks, and if the clicked element contains an attribute called "data-adobe-view", then get its value (i.e. the name of the view) and then fire a triggerView call using that value as a parameter.

 

This is a simple and very scalable solution that satisfies our needs.

 

Here it is:

document.body.addEventListener('click', function(event) { if (event.target.matches('[data-adobe-view]')) { if (typeof adobe !== 'undefined' && !!adobe.target && typeof adobe.target.triggerView === 'function') { adobe.target.triggerView(event.target.dataset.adobeView) } } });

 

This overcame some issues we found with the onclick approach, whereby our use of Rocket Loader (Cloudflare) was interfering as per: https://stackoverflow.com/questions/65449689/cloudflare-seems-to-be-blocking-google-analytics-onclick-events

1 reply

MichaelWillsAuthorAccepted solution
Level 3
January 20, 2023

We were able to find a solution internally with our developers. The solution we came up with involves listening for 'any' clicks, and if the clicked element contains an attribute called "data-adobe-view", then get its value (i.e. the name of the view) and then fire a triggerView call using that value as a parameter.

 

This is a simple and very scalable solution that satisfies our needs.

 

Here it is:

document.body.addEventListener('click', function(event) { if (event.target.matches('[data-adobe-view]')) { if (typeof adobe !== 'undefined' && !!adobe.target && typeof adobe.target.triggerView === 'function') { adobe.target.triggerView(event.target.dataset.adobeView) } } });

 

This overcame some issues we found with the onclick approach, whereby our use of Rocket Loader (Cloudflare) was interfering as per: https://stackoverflow.com/questions/65449689/cloudflare-seems-to-be-blocking-google-analytics-onclick-events