Server Side Google Analytics -- utm variables - coldfusion

So I have set up on my server a page that will be called depending on certain conditions. This script creates the .gif for google analytics and hits their server.
I've confirmed with my clients they're seeing the page hits; however, some want to see UTM variables (utm_campaign, utm_source, utm_term, etc...). I can't seem to get the UTM variables to stay, I've attached them to the tracking string but they look like they're being removed. Will this require the UTME piece?
<cfset TrackingStringFromEDOM = ("http://www.google-analytics.com/__utm.gif?" &
"utmwv=4.4sh&" &
"utmn=#RandRange(0,2000000000)#&" &
"utmhn=#URLEncodedFormat(urlDomainString)#&" &
"utmr=%2D&" &
"utmp=#URLEncodedFormat(utmp)#&" &
"utmac=#googleID#&" &
"utmcc=__utma%3D999.999.999.999.999.1%3B&" &
"utmvid=#id#&" &
"utmip=127.0.0.0"
) />
<cfoutput>#TrackingStringFromEDOM#</cfoutput><br/><br/>
<cfhttp method="get" url="#TrackingStringFromEDOM#" timeout="1000" />

First I would write the variable a bit differently:
<cfset TrackingStringFromEDOM = "http://www.google-analytics.com/__utm.gif?" &
"utmwv=4.4sh&" &
"utmn=" & RandRange(0,2000000000) & "&" &
"utmhn=" & URLEncodedFormat(urlDomainString) & "&" &
"utmr=%2D&" &
"utmp=" & URLEncodedFormat(utmp) & "&" &
"utmac=" & googleID & "&" &
"utmcc=__utma%3D999.999.999.999.999.1%3B&" &
"utmvid=" & id & "&" &
"utmip=127.0.0.0"
/>
Another thing is some parameters don't seem to be in the list of the gif parameters - please check http://code.google.com/intl/en/apis/analytics/docs/tracking/gaTrackingTroubleshooting.html#gifParameters

Related

Power BI connect to CRM 2016 Web API

I'm trying to use Power BI Desktop to connect to a CRM Online (2016 Spring Wave 1) instance using CRM's new Web API methods.
When I put my api into a browser like Chrome I get results back. For example if I use https://xxx.crm.dynamics.com/api/data/v8.0/my_records?$select=my_recordid I can see all the results being listed (in batches of 5000)
However, when I try the same thing in PowerBI I get an error telling me that a field already exists (see screenshot)
I've seen some approaches where the URL is wrapped
= Json.Document(Web.Contents("<same url as above>")
but this doesn't seem like a good approach, and I don't know how to use this approach with paging.
So has anyone managed to get Power BI working with the new Web API calls?
I created a new CRM Online Trial instance and retried using the WebAPI URL (https://xxx.crm.dynamics.com/api/data/v8.0/my_records?$select=my_recordid) in Power BI and this time it worked.
It must be something to do with the customisations that I have in place.
Also, I noticed that even though I included a $select=my_recordid filter in my WebAPI request, that PowerBI still loaded all columns names; however, only the column specified in my filter had values.
This would explain why the error occurs even when I specify a single attribute in the $select
I'm rather late to this question, but I've had good success with the "Json.Document(Web.Contents())" method. The trick to the paging issue was wrapping the call in a recursive function. For convenience, I've wrapped that recursive function such that I can pass in the name of a Saved View/Advanced find and get the results of that query.
As a Gist: https://gist.github.com/d4hines/b5d9900fc1ea9d26311d2145505837cb
(OrgUrl as text, QueryName as text, UserView as logical) =>
let
GetQueryByName =
//https://mycrm.mydomain.com/MYORG
(OrgUrl as text, QueryName as text, UserView as logical) =>
let
QueryType = if UserView then "user" else "saved"
,return = OData.Feed(
OrgUrl & "/api/data/v8.0/" & QueryType & "queries?$select="& QueryType & "queryid&$filter=name eq '" & QueryName & "'"
)[userqueryid]{0}
in
return,
QueryAll =
(nextURL, prev) =>
let
prevList = if prev <> null then prev else {},
responseData = Json.Document(Web.Contents(nextURL, [Headers=[Prefer="odata.include-annotations=""OData.Community.Display.V1.FormattedValue"""]])),
return = if responseData[#"#odata.nextLink"]? <> null then #QueryAll(responseData[#"#odata.nextLink"], prevList & responseData[value]) else responseData[value] & prevList
in return,
NamedQuery = OrgUrl & "/api/data/v8.0/contacts?userQuery=" & GetQueryByName(OrgUrl, QueryName, UserView),
return = Table.FromList(QueryAll(NamedQuery, null), Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in return
There are a bit more instructions on the gist if that helps. Hope it helps someone!

Calling cfoutput within cfscript

I'm using a cftry catch to send an email to our alerts box when a widget on our site fails to load.
the cfcatch.message and cfcatch.detail don't provide enough detail on which page in particular is failing.
We have an attribute r_page which returns the page id when output.
However the email is generated using CFScript. How do i call <cfoutput>"#r_page#"</cfoutput> within my script to display in the email body?
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>
Thanks
If you don't quote it, it will be evaluated automatically in the setBody() method, just like your current cfcatch members are being evaluated.
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. - " & r_page & " Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>
You can also evaluate it inline too using ##.
<cfscript>
mailObj = new mail();
mailObj.setFrom(application.errorEmail);
mailObj.setTo(application.errorEmail);
mailObj.setSubject("THIS IS THE SUBJECT");
mailObj.setBody("A page is broken. - #r_page# Details: " & cfcatch.detail & " Message: "& cfcatch.message);
mailObj.send();
</cfscript>

Variable name in the method of ColdFusion Object

I am trying to set a variable in a cffunction.
The result is this:
<cfset local.layouts.appLayout = '../../app/layouts' & local.appController.new()>
The above code works. In the local.layouts.appLayout structure it assigns the return of the new method in the appControler. That is what I need it to do.
My problem is that I need to dynamically assign the method portion of that statement. I have another variable coreRoute.action that equals "new" in that function but I cannot seem to get the syntax right.
I have tried this:
<cfset local.layouts.appLayout = '../../app/layouts' & local.appController.coreRoute.action()>
That does not work and I can see why. I have also tried this:
<cfset local.layouts.appLayout = '../../app/layouts' & local.appController & #coreRoute.action# & '()'>
I have tried many variations of this syntax and I just cannot get it right.
Anyone have any ideas about how to do this. I am stuck.
Thanks in advance for any help.
UPDATE: With Todd Sharp's help I ended up using this and it worked great:
<cfinvoke component="#local.appController#" method="#coreRoute.action#" returnvariable="local.act">
<cfset local.layouts.appLayout = '../../app/layouts' & local.act>
You should look into using <cfinvoke> for dynamic method invocation. Try a Google search for "coldfusion dynamic method invocation" - here's one of the top results:
http://www.bennadel.com/blog/1320-ColdFusion-CFInvoke-Eliminates-The-Need-For-Evaluate-When-Dynamically-Executing-User-Defined-Functions.htm
In addition, if you want to do it entirely in script, you can, using this approach:
dynFn = this["foo" & bar];
dynFn(stuff);
This is in a cfc, if you're doing it from outside the cfc or not using a cfc at all, just change "this" to wherever your method is.

Signing API requests with Coldfusion

I'm trying to work with the Kelkoo API (http://developer.kelkoo.com/samples/) as part of a project, and I've hit a brick wall when it comes to signing my requests.
As is usual for Coldfusion (sadly!) there are no code samples, and despite studying the other samples given, I really have no clue how to construct this (i.e they don't actually appear to say what they want anywhere!).
Maybe I'm missing something, but any pointers in the right direction would be appreciated!
Use Java's as your sample: http://developer.kelkoo.com/samples/signing-url-java/
var your variables
System.currentTimeMillis() => getTickCount()
+ string concat => & string concat
line 41: tokken = hash(URLtmp & key, "md5", "ISO-8859-1")
hash() returns hex, so you need toBase64(BinaryDecode(tokken, "hex"))
line 42: replaceList(tokken, "+,/,=", ".,_,-")
<cfargument name="urlDomain" type="string" required="false" default="http://fr.shoppingapis.kelkoo.com" hint="kelkoo API domain"/>
<!---
Signature Kelkoo URL
#param urlPath string (required) kelkoo path resources (ex: /V3/productSearch?query=table)
#param secretKey string (required) kelkoo Secret Key
#param trackingId string (required) kelkoo tracking Id
#param urlDomain string (optional) kelkoo API domain default (http://fr.shoppingapis.kelkoo.com)
#author Mauro Cardini (mcardini#decofinder.com)
#version 0, December, 2019
--->
<cfset var theTimeStamp=int(getTickCount()/1000)>
<cfset var URLtmp=arguments.urlPath & "&aid="& arguments.trackingId & "&timestamp=" & theTimeStamp>
<cfset var tokken=hash(URLtmp & arguments.secretKey, "md5", "UTF-8")>
<cfset tokken=toBase64(BinaryDecode(tokken, "hex"))>
<cfset var thetokken=replaceList(tokken, "+,/,=", ".,_,-")>
<cfset URLreturn = arguments.urlDomain & URLtmp & "&hash=" & theTokken>
<cfreturn URLreturn>

Does Classic ASP have an object that I can use to browse and modify DOM elements on the server?

I am working in a classic asp application that requires functionality that will modify code that the user copy and pastes into a form. The user is considered a trusted user who is not familiar with html.
I am trying to make it so that if the user wants to change all width="" attributes in the supplied code then all he has to do is fill a textbox label Width with the correct value and press save/submit. Then the script will find all width attributes and update their values in the html snippet that was supplied.
I've been working on a regular expression to do this, but while researching I read that a lot of people do not recommend regexps for this type of thing and would rather use a html parser object of some sort.
Is there an html parser or DOM browser/editor available in classic asp or do I just need to continue my regexp development?
For the regexp, this is what I have so far... still need to modify it to perform replacements on all matches, not just the first one:
function replaceBetween(sSource, sStart, sStop, sValue)
thisNewValue = sStart & sValue & sStop
set re = new regexp
re.pattern = "(" & "" &sStart & ")(.*?)(" & sStop & ")"
re.IgnoreCase = true
response.write "Pattern: <b>" & re.pattern & "</b><br />" & vbnewline
response.write "thisNewValue: <b>" & thisNewValue & "</b><br />" & vbnewline
response.write "match: <b>" & re.test(sSource) & "</b><br />" & vbnewline
replaceBetween = re.replace(sSource, thisNewValue)
end function
sourceText = ("<div class='thisclass' id=""thisID""><a anotherthing="""" attribute=""one""><a attribute=""2""><a anotherattribute="" attribute=""three 3""></div>")
replacestart = "attribute="""
replacestop = """"
newvalue = "XXXX"
response.write "updated source: <b>" & server.HTMLEncode(replaceBetween(sourceText,replacestart,replacestop,newvalue)) & "</b><br />" & vbnewline
Is your HTML well formed? If so you could simply use an XML DomDocument. Use XPath to find the attributes you want to replace.
You can actually use JScript serverside as well in ASP, whicdh might give you access to HTMLDom libraries you could use.