I am trying to send custom dimensions as data from my app to the google analytics dashboard. I have successfully got screenviews and events showing in Google Analytics.
Below is my code for sending the custom dimension
func logScreenTrackingWithCustomDimension(screenName: String, data: AnyObject) {
let customDimension = data
let tracker = GAI.sharedInstance().defaultTracker
tracker.set(GAIFields.customDimensionForIndex(1), value: customDimension as! String)
tracker.set(kGAIScreenName, value: screenName)
tracker.send(GAIDictionaryBuilder.createScreenView().set(customDimension as! String, forKey: GAIFields.customDimensionForIndex(1)).build() as NSDictionary as [NSObject : AnyObject])
}
the function argument "data" is the string value I am passing in from another controller where I call this function.
I have also set up the dimension correctly within google analytics
P.S i am tracking screenviews and events for the above code and they show up in google analytics. Just not the actual data of the dimension which is not being tracked for some reason
Any help would really be appreciated because I am trying to track a product ID when click on a product screen. This will enable me to see what products are being viewed etc.
Thanks
For dimensions, use this:
let customDimension = data as! String
tracker.set(GAIFields.customDimension(for: UInt(indexNo)), value: customDimension)
Related
I'm trying to find a suitable mechanism to provide an image from the app to the widget. So far I had success with AppGroups and a fixed identifier. Saved the image in user defaults with a fixed ID on the app side and I could retrieve it on the widget side by accessing user defaults with my key.
But now I'm trying to get along with Siri Intents. I don't know how to provide image data from my app to my widget. How can I achieve that? I have seen other PhotoWidget apps on the store that are providing such functionality. For example Photo Widget App shows some UI when editing the widget where I can select a photo that has been chosen on the main app.
To sum up: How can I get a photo chosen from my app inside my widget with SiriIntents?
Any help is appreciated!
In your Intent.intentdefinition file you could add Configurable parameters with Dynamic options:
Then in IntentHandler file you could specify the source for available options. Example for names list from UserDefaults:
class IntentHandler: INExtension, IntentHandling {
func provideNameOptionsCollection(for intent: Intent, searchTerm: String?, with completion: #escaping (INObjectCollection<NSString>?, Error?) -> Void) {
let existingWidgets = UserDefaults(suiteName: "group.name")!.value(forKey: "widgetUnits") as! String
let names = existingWidgets.components(separatedBy: "|")
let result = INObjectCollection<NSString>.init(items: names.map { NSString(string: $0) })
completion(result, nil)
}
}
I have a chat system inside my app. When the user presses send to send the message data to different nodes inside the database -it works fine. The issue I'm having is since I'm using fan out I generate the .childByAutoIdkey before the data is sent. The user presses a send button to start the process but it's always the same exact .childByAutoId key so I'm just overwriting the previous message data. If the user pops the vc and comes back to it then a new key is created but obviously that's terrible ux for a messaging system?
How can I generate different .childByAutoId keys every time the user presses send to fan out?
#obj func sendMessageButtonPressed() {
// ***here's the problem, every time they press send, it's the same exact childByAutoId().key so I'm just overwriting the previous data at the messages/messageId path
guard let messageId = FirebaseManager.Database.database().reference().child("messages")?.childByAutoId().key else { return }
var messageIdDict: [String: Any] = [messageId: "1"]
var messageDict = [String: Any]() // has the fromId, toId, message, and timeStamp on it
let messageIdPath = "messages/\(messageId)"
let fromIdPath = "user-messages/\(currentUserId)"
let toIdPath = "user-messages/\(toId)"
var fanOutDict = [String: Any]()
fanOutDict.updateValue(messageDict, forKey: messageIdPath)
fanOutDict.updateValue(messageIdDict, forKey: fromIdPath)
fanOutDict.updateValue(messageIdDict, forKey: toIdPath)
let rootRef = Database.database().reference()
rootRef?.updateChildValues(fanOutDict)
}
The problem wasn't a new key was not getting generated. #FrankvanPuffelen pointed out in th comments that a new key should get generated every time which is exactly what was happening.
The problem was the fanout was overwriting what was originally written at these 2 paths:
let fromIdPath = "user-messages/\(currentUserId)"
let toIdPath = "user-messages/\(toId)"
It appeared the key was the same because the data kept getting overwritten.
The way I was generating the key works fine
I'm working on WatchKit App. In this app, there are some fields that the user should fill it,
I searched how to deal with input fields in iWatch, and I found the following code:
presentTextInputController(withSuggestions: ["1"], allowedInputMode: WKTextInputMode.plain) { (arr: [Any]?) in
if let answers = arr as? [String] {
if let answer = answers[0] as? String {
self.speechLabel.setText(answer)
}
}
}
and this code gives me two choices: Diction and scribble, i.e
In my App, I want to support only the scribble not both of them,
I tried to pass withSuggestions parameter as nil, but the app direct me to dictiation, not to scribble.
Is there a way to let the user only use scribble?
I know there are some posts about it but I can't find something useful. Therefore, I'm opening new post. I have a device which sends some values over bluetooth. I have function which gets this value like every second. I need to show this data in line chart realtime (Two line). I know Android API has a function for realtime but I can't find it in iOS API.
How I'm doing now is like this;
if (uuid == kUUIDECGSensor) {
let dataDict: [AnyHashable: Any] = LBValueConverter.manageValueElectrocardiography(dataValue)
// print("kUUIDECGSensor dict: \(dataDict)")
let allValues = Array(dataDict.values)
print(allValues)
data_array1.append(allValues[0] as! Double)
data_array2.append(allValues[1] as! Double)
//print(data_array1)
//print(data_array2)
temp_time += 5
time.append("\(temp_time)")
setChart(dataPoints: time, values: data_array1)
}
It is working but It doesnt seem like realtime. What am I missing?
Thank You!
I'm creating a game that uses GameCenter and I'm trying to send and retrieve data.
This is how I'm sending data: (the function 'sendData' is provided by GameCenter with GameKit)
let nick = GCHelper()
let data = NSData(contentsOfFile: "")
try! nick.match.sendData(toAllPlayers: data as! Data, with: .reliable)
'GCHelper' is a class I'm using that contains many functions for Game Center, a download is further through the questions if you're interested. I just needed to call it to access the function.
Then to retrieve data I'm attempting to use this:
nick.match(GKMatch, didReceive: Data, fromPlayer: String)
Note: I have not filled in any of the above parameters
Here is the function I'm using to retrieve the data:
public func match(_ theMatch: GKMatch, didReceive data: Data, fromPlayer playerID: String) {
if match != theMatch {
return
}
delegate?.match(theMatch, didReceiveData: data, fromPlayer: playerID)
}
The function I'm using 'match()' is apart of the GCHelper class. GCHelper allows for you to create GameCenter game easier. Here is a link in case you want to reference it: https://github.com/jackcook/GCHelper
QUESTION
Now that I've showed you all the methods, how would I use the previous method to retrieve data? One of its parameters is 'fromPlayer' and asks for the playerId(String), but how would I know what the other players playerID is? Better yet, how would I retrieve it?
If you don't think this is a good way to handle retrieving data, how could I do it better? Is there another way to do this?
Key Facts:
The game requires 2 people and data is being exchanged between these 2 people only. I need to know how to send and retrieve data amongst the 2.
Thanks for the help! If you have any questions let me know.
This is the function I'm using to retrieve the data:
open func match(_ theMatch: GKMatch, didReceive data: Data, fromPlayer playerID: String) {
}
Now, the data I'm sending is a string. So I create a variable that unarchives the data and sets it to string format.
let myString = NSKeyedUnarchiver.unarchiveObject(with: data) as! String
After this, I need a way to get that string from the view controller or game center file to my game scene. In which I simply just stored the data using UserDefaults.
let user = UserDefaults.standard
user.set(myString, forKey: "myString")
Then in my SKScene I created a timer, in which it checks every couple of seconds to see if there's a change. It stores the values so that when a new values arrives it can compare and if it is different it does something with it, for example: update player points.
Note: This is what I found to work, someone else may have a better way, but it works fine for me.