Skip to main content

Logged-in detection

Logged-in detection lets Triggerbee know whether a visitor is logged in on your website. Once it's set up, every visit gets a login status, which you can use to target campaigns, build audiences and follow how many of your visitors are logged in.

Logged-in detection is included in all plans except Essential.

What you can do with it

  • Target campaigns and audiences. Use the conditions Is logged in and Is logged out to show different experiences to members and anonymous visitors. For example, ask a recognized member to log in to see their member prices.

  • Use the ready-made audiences. Logged in visitors, Logged out visitors, Members logged in and Members not logged in are available as quick-start presets.

  • Follow the Logged in visitors KPI. The dashboard shows the share of visits where the visitor was logged in. Only visits with a detected login status are counted, so visits with an unknown status are left out of the calculation.

  • See logged-in visitors on the dashboard. The traffic chart shows a Logged in visitors line, and the real-time feed marks visits where the visitor is logged in.

  • Break down sales in Web analytics. On the sales chart (revenue, purchases or conversion rate), choose Break down by > Login state to compare logged-in and not logged-in visitors.

  • Compare logged-in visitors in Audience analytics. Add the Logged in audience to see how logged-in visitors behave compared to others. If many visits have no login status, Audience analytics shows the share where login detection failed.

Before you start

You'll need a way for Triggerbee to tell whether someone is logged in. Depending on the method you choose, you may need help from a developer to add a small snippet to your site, or to find the right data layer value, JavaScript expression or page element.

Set up logged-in detection

  1. Go to Settings > Customization > Logged-in detection.

  2. Turn on Enable logged-in detection.

  3. Set up the recommended method (the standardized global), a fallback method, or both. Both are described below.

  4. Click Save.

Changes take effect within a few minutes, once the Triggerbee tracking script has synced.

Recommended: declare the login state yourself

The most reliable option is to have your website tell Triggerbee directly whether the visitor is logged in. It needs no configuration in Triggerbee, only this snippet on your site:

<script>   
window.triggerbee = window.triggerbee || {};
window.triggerbee.userLoggedIn = true; // set to false when the visitor is logged out
</script>
  • Place the snippet on the page before the Triggerbee script.

  • Set the value to true when the visitor is logged in and false when they're logged out.

  • Single-page apps: update window.triggerbee.userLoggedIn, or call window.triggerbee.setUserLoggedIn(true) / window.triggerbee.setUserLoggedIn(false), whenever the login state changes without a page reload.

When this value is present, Triggerbee always uses it first, before any fallback method.

Fallback methods

If you can't add the snippet, you can let Triggerbee work out the login state from something that's already on your site. The fallback is only used when the snippet above is missing. Pick the one method that best fits your site:

Method

Best when

None

You only use the snippet above.

Data layer value

Your site already pushes login status to the data layer (for example via Google Tag Manager).

JavaScript expression

The login status is available in a JavaScript variable on the page.

Page element

Something on the page is only shown to logged-in (or logged-out) visitors, such as an account menu or a login link.

Data layer value

  • Data layer key (required): the key that holds the login status, for example user_login_state.

  • Value that means logged in (optional): for example Logged in. If you leave it empty, any truthy value counts as logged in.

  • Value that means logged out (optional): for example Logged out. You can only fill this in if you've also entered the logged-in value.

Tip: Fill in both values for the most accurate result. Triggerbee then only sets a status when the key matches one of them, and leaves the status blank for any other value, instead of counting the visitor as logged out.

JavaScript expression

  • Expression that means logged in (required): an expression that returns true for logged-in visitors, for example window.app?.user?.isLoggedIn === true.

  • Expression that means logged out (optional): for example window.app?.user === null.

Tip: Fill in both values for the most accurate result. Each expression then only counts when it returns true, so a page that hasn't finished loading leaves the status blank instead of counting the visitor as logged out.

Content Security Policy: This method requires 'unsafe-eval' in your site's script-src. If your site uses a strict Content Security Policy, use the standardized global or the page element method instead.

Page element

  • CSS selector that means logged in: for example .account-menu.

  • CSS selector that means logged out: for example .login-link.

You need at least one of them, but filling in both gives the best accuracy. Triggerbee then only decides when it can see one of the elements, and leaves the status blank if it sees neither. With only one selector, Triggerbee assumes the opposite status whenever that element is missing, which can be wrong while a page is still loading.

Troubleshooting

The dashboard says "Logged-in detection is not set up." Detection is turned off. Go to Settings > Customization > Logged-in detection and enable it.

Audience analytics says "This site does not track logged-in visitors." No logged-in visits have been recorded for the selected period. Check that detection is enabled and set up correctly.

Many visits have no login status, or Audience analytics says "Login detection failed on X% of visits". A correctly configured site reports a status for every visit. Check that the snippet is placed before the Triggerbee script, or that your fallback key, expression or selectors match what's actually on your pages. If you use both a logged-in and a logged-out value, visits that match neither are left blank.

My changes don't seem to apply. Allow a few minutes for the tracking script to sync, then reload your site.

The JavaScript expression method doesn't work. Your site probably has a strict Content Security Policy. Switch to the standardized global or the page element method.

Did this answer your question?