Persistent URL query string throughout the entire site?

耗尽温柔 提交于 2020-01-22 00:41:04

问题


This is one of those situations where I feel like there is a simple answer right in front of me...hopefully you guys/gals can show me the light.

PROBLEM :

I have a client that wants to maintain a query string across all pages on their site, only if they arrived at the site via a link that contains the query string.

This query string would also need to be passed with any external link from the site.

INFORMATION :

An example of the query string :

?utm_medium=<ad_placement>&utm_source=<ad_source>

(Obviously this is for tracking conversions from ads)

We're currently tracking all this stuff via Google Analytics (so, yes, I know that's an alternative), this is for an extra layer of reporting.

I did not code their site, which brings it's own set of issues (example: I'm not even sure they use a common header among all pages) - so I'm hoping there is a KISS answer out there for this.

Any suggestions?


回答1:


If you just want to persist this exact query string on each page, why not set the linked pages to insert the string into a session variable. Then on each page link check to see if the session variable exists and add it to the query string when redirecting.




回答2:


So - the answer here was this :

  1. Use JS to grab the query string
  2. Validate the query string
  3. Add to a cookie
  4. Append the cookie'd query string to every href in the DOM

Like I said...I knew there was a simple example staring me in the face haha!




回答3:


This question is old and obviously must have been solved by now by @aepearson. Adding another answer from current day perspective.

Now, one can also easily use sessionStorage also to save navigation data into a key. Pick it up whenever required, and add to url.

Example from Mozilla

// Save data to sessionStorage
sessionStorage.setItem('key', 'value');

// Get saved data from sessionStorage
var data = sessionStorage.getItem('key');

// Remove saved data from sessionStorage
sessionStorage.removeItem('key');

// Remove all saved data from sessionStorage
sessionStorage.clear();


来源:https://stackoverflow.com/questions/18214497/persistent-url-query-string-throughout-the-entire-site

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!