How can I make this looks better in one line maybe, Instead of using four lines.
Screenshot
By either using a regex or just contains. I would go with a regex. Just test it well. Something like this: sub\.domain\.com\/en(\/|#){0,2}$ I removed the protocol because it's not essential there. You will get it anyway in your GA call, so easy to manipulate the data as you wish.
Tested here: https://regex101.com/r/ZjqXnu/3
Related
i want to create a dynamic remarketing campaign in Google Ads, but i have to let GTM know where to extract the information for ecomm_prodid, ecomm_pagetype, ecomm_totalvalue and ecomm_category from my website. I understand that i have to create a Data Layer Variable but i just don't know how to make those tags extract the necessary info from my website. I also know that you should be able to see in Google Tag Assistant the Metadata for your products (price, brand, category etc) in the Dynamic Remarketing Tag. Unfortunately i cannot add code to my website as it was created on a platform that doesn't allow custom code, so i have to use GTM.
For example the class for the price is: fPrice -g-product-final-price-258. Shouldn't ecomm_totalvalue take info from this class? I tried reading Help pages from google but they are soooo confusing, i cannot understand them.
If anyone would help me with this i would be very grateful.
Thanks
I know this is 10 months late but this might help you or lead someone arriving here to hopefully the right direction and/or solution. I came across your question unanswered when looking for something else. It seems you have two questions so I'll try to answer both.
For starters you might want to have a quick look at the GTM Dynamic Remarketing Documentation.
Question 1: Where to extract the information for [variables] ?
You are on the right track with the dataLayer here. Usually you need to implement that with custom Javascript on your website (which in your case you can't do / see below for that). You would usually populate a events & variables with dataLayer.push() function.
Here is a sample of how that could look:
dataLayer.push({
'event': 'your_event_name',
'a_container_name' : {
'key1' : key_var_1,
'key2' : key_var_2, }
})
You can also do inner structures within those structures (nested dictionary).
Once those are populated you can create variables in Google Tag Manager (GTM) and simply pick up the values with the naming convention you've used separated by a "." (dot). For the above you could for example do: "a_container_name.key1" which would then populate the variable in GTM with the value of "key_var_1".
You can use the event name (here: 'your_event_name') as the trigger for the Tag in GTM to fire your Tag.
So in your case you would usually want the variable "ecomm_prodid" taken from the webpage with a bit of javascript and pushed into the dataLayer for you to pick up in GTM as described.
Question 2: I cannot add code to my website, what can I do ?
While this is entirely possible it is unfortunately a bit more tedious and potentially much more error prone. In this case you have to read the values you want directly from your website through GTM.
You can use custom javascript inside variables in GTM. To do so click on "variables", then click on "New" and select "Custom Javascript". You can then use pretty much any javascript here to basically scrape the value off your website based on id, class or any other HTML identifiers. There are tons of options on how to do that. You have to use what works best for you.
However this is potentially very error prone. Here is why:
You've stated that your class for the price is "fPrice -g-product-final-price-258". This looks to me very much like an auto generated identifier. Next time you look at that product or pick another one it is most likely different. So your option is to take either another unique identifier or use a sub-string of that one (e.g.: fPrice -g-product-final-price only). But keep in mind if your website ever updates or changes those class names the javascript you wrote instantly will not work any longer.
So it is important to pick some robust form of identifier or write the javascript code so that it will last. As mentioned, the jvascript to scrape or read directly off your website can be as custom as you like. Here is a crude example of how this would look like.
var text = ''; // empty value placeholder
if (document.getElementsByClassName("YOUR_SPECIFIC_CLASS_NAME")) {
....loop through returned elements if applicable....
....do stuff here or check stuff here...
text = SOME_ELEMENT.innerHTML;
console.log(text) // helps to debug your code
}
return text
Again this is only a crude example but if you get this to work then you can simply use the populated variable in your Tag in any field that supports variable with the double curly brackets: {{YOU_TAG_MANAGER_VARIABLE_NAME}}
I hope this helps and gives you a bit on an insight. Good luck!
PS: By the way. If you can't edit your code because of your website provider or website engine then I would strongly recommend moving away from it. As you can see it would save you a ton of headache. For smaller to mid sites and smaller e-commerce stores use Wordpress. For larger stuff there are other solutions. In any case there are some website builders out there that are simply really bad but at the same time very misleading. Basically leading you to the problems as you've described. Don't use them :)
I'm going to need to display a list of results as a response from a telegram bot I'm working on, and was wondering what's the best way of doing that...
I could "calculate" the amount of spaces I need to make it look semi-normal, but I'd rather have a better solution, if there is one.
Thanks!
So, the closest solution I could find is using "pre" inside the bot message (assuming it has parseMode=html), since the characters are all the same width.
I won't be using it eventually, but that's my 2 cents..
i prefer generating HTML table as file and then convert it to an image with some tools, and finally send the image to user by sendPhoto method.
by this method i can create a beautiful colored table with many options...
I have used a PHP library to generate a tabular structure, then used <pre> tag to keep the spacing as it is as suggested by trueicecold
I want to create a destination goal in google analytics. The URL is -https://www.dropbox.com/sh/afxvoo7yramakbj/AADdI77nqKL2sT5mIYXxYlyya?dl=0
This part https://www.dropbox.com/sh/ is same in all destination but the later characters vary. what do I need to write to create a regular expression.
Can anyone help me with this ?
Thanks for reading this. Hope you guys have a great day.
with Regards,
Bhola
I'm tempted to say that you should use the wildcard match to match anything and everything after the sh/ like this
^/sh/.*
but this might be too broad for you. But then again that stuff after the sh/ looks too random to find a pattern. If the random stuff is always in this format
https://www.dropbox.com/sh/random_thing/another_random_thing?dl=0
then you could try this pattern
^/sh/.*/.*\?dl=0
Not sure if the query parameter changes either, but you should try to learn a bit of regex to figure that part out if the pattern doesn't work.
It could be a project well beyond my skills right now but I've got around one full month to spend on it so I think I can do it. What I want to build is this: Gather news about a specific subject from various sources. Easy, right? Just get the rss feeds and display them on a page. Well, I want something more advanced: Duplicates removed and customized presentation (that is, be able to define/change the format in which the news headlines are displayed).
I've played a bit with Yahoo Pipes and some other tools and I am facing two big problems:
Some sources don't provide rss feeds. How do I create one?
What's the best method to find and remove duplicates. I thought about comparing the headlines and checking if there is a matching bigger than, say, 50%. Is that a good practice though?
Please add any other things (problems, suggestions, whatever) I might not have considered.
Duplication is a nasty issue. What I eventually ended up doing:
1. Strip out all HTML tags except for links (Although I started using regex, I was burned. I eventually moved to custom parsing to remove tags)
2. Strip out all whitespace
3. Case-desensitize
4. Hash all that with MD5.
Here's why you leave the link in:
A comment might be as simple as "Yes, this sucks". "Yes, this sucks" could be a common comment. BUT if the text "this sucks" is linked to different things, then it is not a duplicate comment.
Additionally, you will find that HTML tag escaping is weird with RSS feeds. You would think that a stray < would be double-encoded: (I think)&<;
But it is not. It is encoded <
But so too are HTML tags! :<p>
I eventually copied all the known HTML tags as parsed by Mozilla Firefox and manually recognized those tags.
Creating an RSS feed from HTML is quite nasty and I can only point you to services such as Spinn3r, which are fantastic at de-duplication and content extraction. These services typically use probability-based algorithms that are above me. I know of one provider that got away with regexing pages (They had to know that a certain page was MySpace-based or Blogger-based) but they did not perform admirably.
You might want to try to use the YQL module to scrape a webpage that doesn't provide RSS. Here's a sample of a YQL statement to scrape HTML.
About duplicates, take a look at this pipe.
Customized presentation: if you want it truly customized you'll have to manipulate the pipe results yourself, e.g. get it as JSON an manipulate it with Javascript, or process it server-side.
Should HtmlEncode() be abandoned and Replace() used instead of I want to parse links in posts/comments (with regular expressions)? HtmlEncode() replaces & with & which I assume can cause problems with links, should I just use Replace() to replace < with <?
For example if a user posts something like:
See this site http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3
I want it to be:
See this site <a href="http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3">http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3</a>
But With HtmlEncode() the URL will become (notice the ampersand):
See this site http://www.somesite.com/somepage.aspx?qs1=1&qs2=2&qs3=3
Should I avoid the problem by using Replace() instead?
Thanks
Actually, your last example - the one you're worried about - is the only correct one. In HTML documents, ampersands are used to introduce entity references, and therefore must be escaped. While most browsers are forgiving enough to let them slip through when not obviously part of an entity reference, you can run into subtle problems should their use in a URL happen to look like an entity.
Let HtmlEncode() do its job.
Perhaps you are looking for UrlEncode()?
http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
What are you looking to replace and why? HtmlEncode() is typically used to sanitize user-supplied data. That said, if you're allowing users to submit links, you probably don't want to HtmlEncode them, in the first place. You're basically going to render them exactly as the user supplied them.
Replacing & with & inside of an href attribute is correct. If you do not, then your code is technically invalid. Also, you should escape it even if it's inside of a link. The only case you'll run into problems is if you end up HTMLEncoding it multiple times.
I recommend against using Replace to do the job of HTMLEncode or URLEncode. These functions are custom designed to take care of most of the problems that you'd see in user entered content and if you try to replace them with your own code, the results might get ugly (I am talking from experience here) if you forgot something vital.