Solved

Track user "Active on Site" event from server side

  • 29 March 2021
  • 6 replies
  • 142 views

Userlevel 1
Badge

Hi,

I created custom tag Klaviyo tag for Google Tag Manager Server Side

And use it on my site for tracking user events as an alternative to Klaviyo JS library. (I do this for better page speed. In my case your js library does not download to the user browser.)

My solution uses your server side api

But I have an issue with tracking "Active on Site". I don't find a way to do this from server side. 


1) Is there a possibility to track this on server side or I can do this only with your JS script?

2) Do you plan to add this option to the server side api?

3) Maybe you have a workaround for this now?

icon

Best answer by cbarley 29 March 2021, 21:51

Hey @gtm-server , cool you’re developing a Server Side tag! I’ve been working though that tool for a bit to see how it works and it’s really interesting.

To answer your question, there are a couple ways to figure out how to spoof an Active On Site event through the Serverside API. The best way to tell is from the network tab in the Chrome Dev Tools, but there’s technically 2 ways to spoof it:

  1. On any onsite event, include $is_session_activity=true. It gets picked up and used to generate/update an Active on Site event with a new url and timeframe.
  2. To track it just by itself (ie to mimic a person just bouncing around on the page and not triggering other events) there’s a specific event name and structure. Here’s an example that I sent from my own account:

    {
    "event":"__activity__",
    "token":"PUBLIC_KEY",
    "properties":{
    "page":"https://website.com/",
    "browser":"Chrome",
    "os":"Mac",
    "$use_ip":true,
    "$is_session_activity":true
    },
    "customer_properties":{
    "$email":"email here",
    "$referrer":{
    "ts":1614270576,
    "value":"",
    "first_page":"https://website.com/"
    },
    "$last_referrer":{
    "ts":1617046396,
    "value":"",
    "first_page":"https://website.com/"
    }
    }
    }

    Referrer and last referrer are necessary though, those are just reserved profile properties that hydrate that “how they found you” section on a profile, which our cookie tracks by default

Let me know if you have follow up questions after testing!

-Connor

View original

6 replies

Userlevel 2

Hey @gtm-server , cool you’re developing a Server Side tag! I’ve been working though that tool for a bit to see how it works and it’s really interesting.

To answer your question, there are a couple ways to figure out how to spoof an Active On Site event through the Serverside API. The best way to tell is from the network tab in the Chrome Dev Tools, but there’s technically 2 ways to spoof it:

  1. On any onsite event, include $is_session_activity=true. It gets picked up and used to generate/update an Active on Site event with a new url and timeframe.
  2. To track it just by itself (ie to mimic a person just bouncing around on the page and not triggering other events) there’s a specific event name and structure. Here’s an example that I sent from my own account:

    {
    "event":"__activity__",
    "token":"PUBLIC_KEY",
    "properties":{
    "page":"https://website.com/",
    "browser":"Chrome",
    "os":"Mac",
    "$use_ip":true,
    "$is_session_activity":true
    },
    "customer_properties":{
    "$email":"email here",
    "$referrer":{
    "ts":1614270576,
    "value":"",
    "first_page":"https://website.com/"
    },
    "$last_referrer":{
    "ts":1617046396,
    "value":"",
    "first_page":"https://website.com/"
    }
    }
    }

    Referrer and last referrer are necessary though, those are just reserved profile properties that hydrate that “how they found you” section on a profile, which our cookie tracks by default

Let me know if you have follow up questions after testing!

-Connor

Userlevel 1
Badge

Thank you for such a fast response. This helps me a lot. Now I get "Active on Site" for users correctly.

Example of what I exactly send to the Klaviyo:

 

{
  "token": "xxxYYY",
  "event": "__activity__",
  "customer_properties": {
    "$email": "example@gmail.com",
    "$last_referrer": {
      "ts": 1617187952,
      "value": "",
      "first_page": "https://google.com/"
    }
  },
  "properties": {
    "$is_session_activity": true,
    "$use_ip": true,
    "page": "https://demo.example.com/"
  },
  "time": 1617187952
}

 

I don't have the ability to determine "browser" and "os" on the GTM Server Side, for now, so I don't send them.
Also, I added the "X-Forwarded-For" header to this request and send the user IP there.


All works great, but I still have one small question) What do you think is this good idea to send page referer into "customer_properties.last_referrer"? Is this field for page refer or more like for user start page?

Userlevel 1
Badge

Klaviyo tag for GTM Server Side now available in Template Gallery. 

https://tagmanager.google.com/gallery/#/owners/gtm-server/templates/klaviyo-tag

 

And here is a guide for how to use it https://gtm-server.com/integrate-klaviyo-with-your-website-using-google-tag-manager-server-container/ 

 

Thanks for support and great service.

Userlevel 2

@gtm-server not sure how, but I’m just seeing this now! Looks awesome. I downloaded the template to my GTM environment and will test it out. Awesome to see this work going on. Nicely done :) 

Hey @cbarley,

Our preference is as well to have everything server side but how does Klaviyo will track cross browser emails clicks. I see a fragment of code on the client side script from Klaviyo which basically parses the url to extract email from utm_email or get the klaviyo keys _ke /_kx and identify the user again.

Does Klaviyo still do similar identification on server side?

Userlevel 1
Badge

@gtm-server not sure how, but I’m just seeing this now! Looks awesome. I downloaded the template to my GTM environment and will test it out. Awesome to see this work going on. Nicely done :) 

@cbarley  Do you have any questions or suggestions? 

I will appreciate any feedback.

Reply