How to use Page View meta data from the JS SDK

  • 15 November 2023
  • 3 replies

Does anyone have experience or tips on how I can use the meta data such as referrer from the JS SDK to create a Event or update an attribute? 

3 replies

Userlevel 1

Hello @Andreas  👋

Page Views event data isn’t accessible right now I’m afraid. We do have an open feature request around this which I will upvote on your behalf. 

As a workaround, it might be possible to capture this data on your web app but we can’t detail exactly the steps to do this.

If you have development resources, you could capture the Page View data and pass that in an identify call from your backend.

You could also pass that along to your website's front end as additional data added to the request headers. When the "identify" call is made from the JS Snippet, you could pass that info along as a profile attribute.

I hope that helps!




Check below steps-

  1. Access referrer information using document.referrer.
  2. Use SDK functions (track or logEvent) to record custom events based on referrer conditions.
  3. Update user attributes using SDK functions or API calls, associating users and setting properties.
  4. Implement conditional logic with if statements to check referrer and trigger actions accordingly.
  5. Employ event listeners/hooks provided by the SDK for capturing events like page load.
  6. Implement error handling for cases where referrer info is unavailable.

Hello @Andreas

As per my knowledge 

Certainly! Utilizing metadata, such as the referrer, can be valuable in tracking user behavior and making data-driven decisions. In a JavaScript context, you can capture and use this information using various methods. Below, I'll provide a general example using JavaScript to access the referrer and then use it to trigger an event or update an attribute.

Assuming you are working with a web page and have access to the DOM, you can use the document.referrer property to get the URL of the referring page. Here's an example:

// Get the referrer
var referrer = document.referrer;

// Assuming you're using a tracking library like Google Analytics
// You might push an event or update a custom dimension

// Example with Google Analytics
if (typeof ga === 'function') {
// Track an event
ga('send', 'event', 'Referrer', 'Page View', referrer);

// Or update a custom dimension
ga('set', 'dimension1', referrer);
ga('send', 'pageview'); // To send the updated data

// Example with another analytics tool or a custom tracking system
// Replace the following lines with the appropriate code for your platform

// Track an event
// trackEvent('Referrer', 'Page View', referrer);

// Or update an attribute
// updateUserAttribute('referrer', referrer);

Remember to replace the examples with the actual code for your analytics or tracking system. The concept is to retrieve the referrer using document.referrer and then use that information to trigger an event or update an attribute within your analytics system.

Please note that relying on document.referrer might have limitations, and in some cases, it might be empty or not contain the expected information. It depends on the browser and user settings. Additionally, some analytics platforms might have specific methods for handling referrer information, so be sure to consult their documentation for the best practices.



Jack Smith