Setting up Triggerbee for a SPA - Single Page App

Much of the functionality in Triggerbee revolves around recording web traffic and that page views are being logged. Normally page views are automatically logged to Triggerbee, if the tracking script is present on the page.

But if you are running a website that is setup as a SPA - Single Page App you need to configure Triggerbee a bit in order for it to work for you in the way it is suppose to.

What is a SPA - Single Page App?

Single-Page Applications (SPAs) are Web apps that load asingle HTML page and dynamically update that page as the user interacts with the app. SPAs use javascript and HTML5 to create fluid and responsive Web apps, without constant page loads. However, this means much of the work happens on the client side, in JavaScript.

So since there are no real page loads the Triggerbee tracking script doesn't register that the user shifts from one page to another. Modern browsers location field can also be dynamically updated using script so the page views become completely virtual and appear to have loaded an entire page although it is just javascript.

Visitor Analytics

To get the visitor analytics to work you need to log each "virtual page view" using the Triggerbee Javascript API.

Add the following example lines in your script where you change pages:

mtr.log("/services", "Services");
	

More reading: 

Widgets

If you also want to have widgets working normally, then you must call on the method mtr_conversion.Init() in your script where you change pages.

This is required if you want to trigger a widget on page load or perhaps using the rule to open a widget after a number of pageviews.

Like this:

if (typeof mtr_conversion !== 'undefined') { mtr_conversion.Init();}

Opening Widgets on certain URLs

If you are programmatically changing the URL that is logged to Triggerbee you need to be aware that the Widgets will only respond to the URL visible in the browser. 

For example, let's say that your SPA web opens a URL with the path /articles/1234567/qwerty/  but you log /articles/sports/bjorn-borg-wins-wimpledon to Triggerbee using mtr.custom.href. If you want a Widget to appear on this page you need to enter the path /articles/1234567/qwerty/ in the Widget Campaign editor.

Did this answer your question? Thanks for the feedback! Please reach out to support@triggerbee.com if there's anything you'd like to add. There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us