Solved

Track user "Active on Site" event from server side


Userlevel 1
Badge +3

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

View original

10 replies

Userlevel 3
Badge +5

@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 :) 

Userlevel 1
Badge +3

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 3
Badge +5

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 3
Badge +5

Hey @Stape , If you want to use the _kx parameter in your requests (_ke is now deprecated), you can actually pass the raw value of the exchange_id that you can get in the console ( by running _learnq.push([“_getIdentifiers”]) ), and using that in a serverside request instead of $email. Example Track Payload: 
 

{
"event": "Blah",
"token": "ABC123",
"customer_properties": {
"$exchange_id": "abcdefghijklmnop"
},
"properties": {
"test": "test"
}
}

Is this what you’re looking for? 

 

Also to your previous question, the container looks great, nothing that jumps out at me at the moment.

Userlevel 1
Badge +3

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?

Badge +2

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 +3

@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.

Userlevel 1
Badge +3

@Vineet Mehenwal Do you find any solution to use klaviyo keys _ke /_kx for identification of user?

 

@cbarley May be some updates on this. This will helps a lot.

Userlevel 1
Badge +3

Awesome. That’s what I need. Thanks for the answer. Now server-side tag will be almost the same as for the web.

I already checked, but for double confirmation is this true:

_kx === $exchange_id

 

Userlevel 3
Badge +5

Hi @Stape yes thats exactly right!

Reply